Class: VagrantPlugins::Lifecycle::Command
- Inherits:
-
Object
- Object
- VagrantPlugins::Lifecycle::Command
- Defined in:
- lib/vagrant-lifecycle/command.rb
Class Method Summary collapse
Instance Method Summary collapse
- #execute ⇒ Object
-
#order_recognized!(parser, args) ⇒ Object
Like OptionParser.order!, but leave any unrecognized –switches alone.
Class Method Details
.synopsis ⇒ Object
4 5 6 |
# File 'lib/vagrant-lifecycle/command.rb', line 4 def self.synopsis "provisions the vagrant machine using a custom lifecycle event" end |
Instance Method Details
#execute ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/vagrant-lifecycle/command.rb', line 20 def execute = Hash.new opt_parser = OptionParser.new do |parser| parser.on("-e", "--event EVENT", "Lifecycle event to execute") do |p| [:event] = p end order_recognized!(parser, ARGV) end opt_parser.program_name="vagrant lifecycle" unless .key?(:event) @env.ui.error "Lifecycle event parameter missing!" puts opt_parser.help exit 1 end lifecycle_event = [:event] with_target_vms([], reverse: true) do |machine| machine.action(:provision, {:lifecycle_event => lifecycle_event}) end exit 0 end |
#order_recognized!(parser, args) ⇒ Object
Like OptionParser.order!, but leave any unrecognized –switches alone
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/vagrant-lifecycle/command.rb', line 9 def order_recognized!(parser, args) extra_opts = [] begin parser.order!(args) {|a| extra_opts << a} rescue OptionParser::InvalidOption => e extra_opts << e.args[0] retry end args[0, 0] = extra_opts end |