Class: MonkeyLens::CLI

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of CLI.



14
15
16
17
18
# File 'lib/monkey_lens/cli.rb', line 14

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

Class Method Details

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



9
10
11
# File 'lib/monkey_lens/cli.rb', line 9

def run(argv, out: $stdout, err: $stderr)
  new(argv, out:, err:).run
end

Instance Method Details

#runObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/monkey_lens/cli.rb', line 20

def run
  command = @argv.shift
  case command
  when "capture" then capture
  when "check" then check
  when "diff" then diff
  when "inspect" then inspect_target
  when "doctor" then doctor
  when "version", "--version", "-v" then version
  when nil, "help", "--help", "-h" then help
  else
    @err.puts "Unknown command: #{command}"
    help(@err)
    2
  end
rescue OptionParser::ParseError, MonkeyLens::Error, Errno::ENOENT => error
  @err.puts "MonkeyLens error: #{error.message}"
  2
end