Class: Opsup::CLI

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

Defined Under Namespace

Classes: OptionBuilder

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app:, option_builder:) ⇒ CLI



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

def initialize(app:, option_builder:)
  @app = app
  @option_builder = option_builder
end

Class Method Details

.createObject



9
10
11
12
13
14
# File 'lib/opsup/cli.rb', line 9

def self.create
  new(
    app: Opsup::App.create,
    option_builder: Opsup::CLI::OptionBuilder.create,
  )
end

Instance Method Details

#run(argv) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/opsup/cli.rb', line 21

def run(argv)
  parser = create_parser
  @option_builder.define_options(parser)

  options = {}
  begin
    # It automatically exits with a help message if necessary.
    commands = parser.parse(argv, into: options)
  rescue OptionParser::MissingArgument => e
    puts e.message
    return false
  end

  begin
    config = @option_builder.generate_config(options)
    @app.run(commands, config)
  rescue Opsup::Error => e
    puts "Error: #{e.message}"
    return false
  end

  true
end