Class: VagrantPlugins::ProviderZone::Command::GuestPowerControls
- Inherits:
-
Object
- Object
- VagrantPlugins::ProviderZone::Command::GuestPowerControls
- Defined in:
- lib/vagrant-zones/command/guest_power_controls.rb
Overview
This is used to manage the power controls for the zone
Instance Method Summary collapse
- #execute ⇒ Object
- #help ⇒ Object
-
#initialize(argv, env) ⇒ GuestPowerControls
constructor
A new instance of GuestPowerControls.
Constructor Details
#initialize(argv, env) ⇒ GuestPowerControls
Returns a new instance of GuestPowerControls.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/vagrant-zones/command/guest_power_controls.rb', line 8 def initialize(argv, env) @main_args, @sub_command, @sub_args = split_main_and_subcommand(argv) @subcommands = Vagrant::Registry.new @subcommands.register(:restart) do require File.('restart_guest', __dir__) RestartGuest end @subcommands.register(:shutdown) do require File.('shutdown_guest', __dir__) ShutdownGuest end super end |
Instance Method Details
#execute ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/vagrant-zones/command/guest_power_controls.rb', line 23 def execute if @main_args.include?('-h') || @main_args.include?('--help') # Print the help for all the vagrant-zones commands. return help end command_class = @subcommands.get(@sub_command.to_sym) if @sub_command return help if !command_class || !@sub_command @logger.debug("Invoking command class: #{command_class} #{@sub_args.inspect}") # Initialize and execute the command class command_class.new(@sub_args, @env).execute end |
#help ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/vagrant-zones/command/guest_power_controls.rb', line 38 def help opts = OptionParser.new do |subopts| subopts. = 'Usage: vagrant zone control <subcommand> [<args>]' subopts.separator '' subopts.separator 'Available subcommands:' # Add the available subcommands as separators in order to print them # out as well. keys = @subcommands.map { |(key, _value)| key.to_s }.sort keys.each do |key| subopts.separator " #{key}" end subopts.separator '' subopts.separator 'For help on any individual subcommand run `vagrant zone control <subcommand> -h`' end @env.ui.info(opts.help, :prefix => false) end |