Class: Necropsy::CLI

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

Constant Summary collapse

HEALTH_FAILURE_STATUS =
3

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(run_id_generator: nil, environment: ENV) ⇒ CLI

Returns a new instance of CLI.



22
23
24
25
# File 'lib/necropsy/cli.rb', line 22

def initialize(run_id_generator: nil, environment: ENV)
  @run_id_generator = run_id_generator
  @environment = environment
end

Class Method Details

.run(argv) ⇒ Object



18
19
20
# File 'lib/necropsy/cli.rb', line 18

def self.run(argv)
  new.run(argv)
end

Instance Method Details

#run(argv) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/necropsy/cli.rb', line 27

def run(argv)
  command = argv.first&.start_with?('-') ? 'analyze' : argv.shift || 'analyze'
  options = default_options
  parser = build_parser(options)
  parser.parse!(argv)
  if options[:help]
    puts parser
    return 0
  end
  if options[:version]
    puts Necropsy::VERSION
    return 0
  end
  apply_config_defaults(options) unless command == 'semantics'

  case command
  when 'analyze'
    report = analyze(options)
    emit_report(report, options, min_confidence: options[:min_confidence])
    health_acceptable?(report, options, strict: false) ? 0 : HEALTH_FAILURE_STATUS
  when 'baseline'
    baseline(options, argv)
  when 'check'
    check(options)
  when 'quarantine'
    quarantine(options)
  when 'bench'
    bench(options)
  when 'record'
    record(options, argv)
  when 'coverage'
    coverage(options, argv)
  when 'semantics'
    semantics(options, argv)
  when 'why', 'why-not', 'explain'
    diagnose(command, options, argv)
  else
    warn "Unknown command: #{command}"
    warn parser
    2
  end
rescue OptionParser::ParseError, Psych::Exception, Error, GraphSelfCheck::Failure => e
  warn e.message
  2
end