Class: Moonshot::CommandLineDispatcher
- Inherits:
-
Object
- Object
- Moonshot::CommandLineDispatcher
- Defined in:
- lib/moonshot/command_line_dispatcher.rb
Instance Method Summary collapse
- #dispatch! ⇒ Object
-
#initialize(command, klass, args) ⇒ CommandLineDispatcher
constructor
A new instance of CommandLineDispatcher.
Constructor Details
#initialize(command, klass, args) ⇒ CommandLineDispatcher
Returns a new instance of CommandLineDispatcher.
5 6 7 8 9 |
# File 'lib/moonshot/command_line_dispatcher.rb', line 5 def initialize(command, klass, args) @command = command @klass = klass @args = args end |
Instance Method Details
#dispatch! ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/moonshot/command_line_dispatcher.rb', line 11 def dispatch! # Look to see if we're allowed only to run in certain accounts, or # not allowed to run in specific accounts. check_account_restrictions # Allow any mechanisms or plugins to hook into this CLI command. handler = @klass.new parser = build_parser(handler) parser.parse! req_arguments = handler.method(:execute).parameters.select { |arg| arg[0] == :req } if ARGV.size < req_arguments.size warn handler.parser.help raise "Invalid command line for '#{@command}'." end handler.execute(*@args) end |