Class: Foruiman::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/foruiman/cli.rb

Overview

Foreman's Thor command structure with an interactive supervisor.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure? ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/foruiman/cli.rb', line 29

def self.exit_on_failure?
  true
end

.is_thor_reserved_word?(word, type) ⇒ Boolean

rubocop:disable Naming/PredicatePrefix -- Thor's extension API

Returns:

  • (Boolean)


25
26
27
# File 'lib/foruiman/cli.rb', line 25

def self.is_thor_reserved_word?(word, type) # rubocop:disable Naming/PredicatePrefix -- Thor's extension API
  word == "run" ? false : super
end

Instance Method Details

#check ⇒ Object



78
79
80
81
82
83
84
85
86
# File 'lib/foruiman/cli.rb', line 78

def check
  engine = build_engine
  engine.validate_ports!
  puts "valid Procfile (#{engine.process_names.join(', ')})"
rescue Foruiman::Error, SystemCallError => e
  raise Thor::Error, e.message
ensure
  engine&.close
end

#run(*args) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/foruiman/cli.rb', line 61

def run(*args)
  raise Foruiman::Error, "run requires a command" if args.empty?

  config = configuration
  env = config.environment
  command = Foruiman::Procfile.new(config.procfile)[args.first] if args.size == 1 && File.file?(config.procfile)
  if command
    exec(env, "/bin/sh", "-c", command, chdir: config.root, unsetenv_others: true)
  else
    # Preserve argv, terminal input, signals and the command's exact exit code.
    exec(env, [args.first, args.first], *args.drop(1), chdir: config.root, unsetenv_others: true)
  end
rescue Foruiman::Error, SystemCallError => e
  raise Thor::Error, e.message
end

#start(process = nil) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/foruiman/cli.rb', line 35

def start(process = nil)
  engine = build_engine
  engine.select(process) if process
  engine.validate_ports!
  interactive = configuration.tui? && $stdin.tty? && $stdout.tty?
  diagnostics = Foruiman::Diagnostics.new(interactive: interactive)
  code = if interactive
           require_relative "tui/application"
           Foruiman::TUI::Application.new(engine).run
         else
           Foruiman::Plain.new(engine).run
         end
  exit(code)
rescue Foruiman::Error, SystemCallError => e
  raise Thor::Error, e.message
rescue StandardError => e
  diagnostics&.error(e)
  warn "foruiman: #{e.message}#{" (details: #{diagnostics.path})" if diagnostics&.path}"
  exit(1)
ensure
  engine&.close
  diagnostics&.close
end

#version ⇒ Object



89
90
91
# File 'lib/foruiman/cli.rb', line 89

def version
  puts Foruiman::VERSION
end