Class: RailsDoctor::CLI

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

Constant Summary collapse

FORMATS =
%w[terminal json markdown html].freeze

Instance Method Summary collapse

Constructor Details

#initialize(argv, stdout: $stdout, stderr: $stderr, env: ENV) ⇒ CLI

Returns a new instance of CLI.



27
28
29
30
31
32
# File 'lib/rails_doctor/cli.rb', line 27

def initialize(argv, stdout: $stdout, stderr: $stderr, env: ENV)
  @argv = argv.dup
  @stdout = stdout
  @stderr = stderr
  @env = env
end

Instance Method Details

#runObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rails_doctor/cli.rb', line 34

def run
  command = @argv.first&.start_with?("-") ? "scan" : (@argv.shift || "scan")
  case command
  when "scan" then run_scan
  when "init" then run_init
  when "agent" then run_agent
  when "validate-config" then run_validate_config
  when "version", "--version", "-v" then @stdout.puts VERSION; 0
  when "help", "--help", "-h" then @stdout.puts(help); 0
  else
    @stderr.puts "Unknown command #{command.inspect}"
    @stderr.puts help
    1
  end
rescue Error => error
  @stderr.puts "rails-doctor: #{error.message}"
  1
end