Class: CommandOptionsParser

Inherits:
Object show all
Defined in:
lib/maws/command_options_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ CommandOptionsParser

Returns a new instance of CommandOptionsParser.



4
5
6
# File 'lib/maws/command_options_parser.rb', line 4

def initialize(config)
  @config = config
end

Instance Method Details

#process_command_options(command) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/maws/command_options_parser.rb', line 8

def process_command_options(command)
  banner_text = usage(@config.profile.name, @config.command_name)
  banner_text << "\n#{command.description}\n\n"
  banner_text << "options:\n"
  command_opts = Trollop::options do
    banner banner_text
    command.add_generic_options(self)
    command.add_specific_options(self)
  end

  @config.command_line.merge!(command_opts)
end

#usage(profile = nil, command = nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/maws/command_options_parser.rb', line 21

def usage(profile = nil, command = nil)
  profile ||= 'profile'
  command ||= 'command'
  <<-EOS

MAWS - Toolset for provisioning and managing AWS

Usage:
     maws.rb #{profile} #{command} [options]

profiles: #{@config.config.available_profiles.keys.join(', ')}
commands: #{@config.config.available_commands.keys.join(', ')}

  EOS
end