Module: Vagrant::Smartos::Zones::Command::MultiCommand
- Included in:
- Dataset, GlobalZone, Smartos, Zones
- Defined in:
- lib/vagrant/smartos/zones/commands/multi_command.rb
Overview
Requires
Define a COMMANDS constant, which is an array of method names:
COMMANDS = %w(subcommand other_subcommand)
Define an OPTION_PARSER constant, which is an instance of an OptionParser
Instance Method Summary collapse
-
#execute ⇒ Object
Automatically called by Vagrant when running a command.
- #fail_options! ⇒ Object
- #option_parser ⇒ Object
-
#process_subcommand ⇒ Object
Sends parsed argv to an instance method that maps to the subcommand name.
- #subcommands ⇒ Object
Instance Method Details
#execute ⇒ Object
Automatically called by Vagrant when running a command
16 17 18 |
# File 'lib/vagrant/smartos/zones/commands/multi_command.rb', line 16 def execute process_subcommand end |
#fail_options! ⇒ Object
40 41 42 43 |
# File 'lib/vagrant/smartos/zones/commands/multi_command.rb', line 40 def @env.ui.warn option_parser.to_s, prefix: false exit 1 end |
#option_parser ⇒ Object
45 46 47 |
# File 'lib/vagrant/smartos/zones/commands/multi_command.rb', line 45 def option_parser @option_parser ||= self.class.const_get('OPTION_PARSER') end |
#process_subcommand ⇒ Object
Sends parsed argv to an instance method that maps to the subcommand name. If flags are passed to the option parser, they will be included in argv as a trailing hash.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/vagrant/smartos/zones/commands/multi_command.rb', line 23 def process_subcommand @options = {} args = (option_parser) exit unless args command = args.shift command_method = subcommands.find { |c| c == command } unless command_method @env.ui.warn option_parser.to_s, prefix: false exit 1 end args << @options unless @options.empty? send command, *args end |
#subcommands ⇒ Object
49 50 51 |
# File 'lib/vagrant/smartos/zones/commands/multi_command.rb', line 49 def subcommands self.class.const_get('COMMANDS') end |