Class: Wurk::Preflight::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/wurk/preflight/command.rb

Overview

The command line for wurk preflight and wurk verify. Exit status: 0 clean, 1 findings, 2 could not run.

Constant Summary collapse

CLEAN_RUN_FAILED =
2

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv, config, out, err) ⇒ Command

Returns a new instance of Command.



20
21
22
23
24
25
26
27
# File 'lib/wurk/preflight/command.rb', line 20

def initialize(argv, config, out, err)
  @name = argv.first
  @argv = argv.drop(1)
  @config = config
  @out = out
  @err = err
  @opts = { limit: DEFAULT_LIMIT, sample: DEFAULT_SAMPLE, pause_ms: 5 }
end

Class Method Details

.run(argv, config: Wurk.configuration, out: $stdout, err: $stderr) ⇒ Object



16
17
18
# File 'lib/wurk/preflight/command.rb', line 16

def self.run(argv, config: Wurk.configuration, out: $stdout, err: $stderr)
  new(argv, config, out, err).call
end

Instance Method Details

#call ⇒ Object

rubocop:disable Metrics/AbcSize



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/wurk/preflight/command.rb', line 29

def call # rubocop:disable Metrics/AbcSize
  parser.parse!(@argv)
  boot_app if @opts[:app]
  report = run_command(read_config)
  @out.puts(redact(@opts[:json] ? report.to_json : report.to_text))
  report.exit_status
rescue ::OptionParser::ParseError => e
  fail_with("#{e.message}\n#{parser}")
rescue ::RedisClient::Error => e
  fail_with("cannot read Redis: #{e.class}: #{e.message}")
rescue ::StandardError, ::ScriptError => e
  fail_with("#{e.class}: #{e.message}")
end