Class: Bootprint::CLI

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

Constant Summary collapse

EXIT_OK =
0
EXIT_POLICY =
1
EXIT_CONFIG =
2
EXIT_SNAPSHOT =
3
EXIT_INTERNAL =
4

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv, out:, err:) ⇒ CLI

Returns a new instance of CLI.



20
21
22
23
24
# File 'lib/bootprint/cli.rb', line 20

def initialize(argv, out:, err:)
  @argv = argv.dup
  @out = out
  @err = err
end

Class Method Details

.start(argv = ARGV, out: $stdout, err: $stderr) ⇒ Object



16
17
18
# File 'lib/bootprint/cli.rb', line 16

def self.start(argv = ARGV, out: $stdout, err: $stderr)
  new(argv, out:, err:).run
end

Instance Method Details

#runObject



26
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
# File 'lib/bootprint/cli.rb', line 26

def run
  command = @argv.shift
  case command
  when "capture" then capture
  when "diff" then diff
  when "diagnose" then diagnose
  when "doctor" then doctor
  when "verify" then verify
  when "fix" then fix
  when "policy" then policy_command
  when "snapshot" then snapshot_command
  when "docker" then docker_command
  when "ci" then ci_command
  when "security" then security_command
  when "version", "--version", "-v" then version
  when "help", "--help", "-h", nil then help(EXIT_OK)
  else
    @err.puts "Unknown command: #{command}"
    help(EXIT_CONFIG)
  end
rescue InvalidSnapshotError => error
  @err.puts "bootprint: #{error.message}"
  EXIT_SNAPSHOT
rescue OptionParser::ParseError, ConfigurationError => error
  @err.puts "bootprint: #{error.message}"
  EXIT_CONFIG
rescue DockerError, PluginError, Errno::EACCES, Errno::ENOENT => error
  @err.puts "bootprint: #{error.message}"
  EXIT_INTERNAL
rescue StandardError => error
  @err.puts "bootprint: internal error: #{error.class}: #{Sanitizer.text(error.message)}"
  @err.puts error.backtrace if ENV["BOOTPRINT_DEBUG"] == "1"
  EXIT_INTERNAL
end