Class: VagrantPlugins::Group::Command
- Inherits:
-
Object
- Object
- VagrantPlugins::Group::Command
- Defined in:
- lib/vagrant-group/command.rb
Constant Summary collapse
- COMMANDS =
%w(up halt destroy provision hosts)
Class Method Summary collapse
Instance Method Summary collapse
-
#execute ⇒ Object
self.synopsis.
Class Method Details
.synopsis ⇒ Object
7 8 9 |
# File 'lib/vagrant-group/command.rb', line 7 def self.synopsis "runs vagrant command on specific group of VMs" end |
Instance Method Details
#execute ⇒ Object
self.synopsis
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/vagrant-group/command.rb', line 11 def execute = {} opts = OptionParser.new do |o| o. = sprintf("Usage: vagrant group <group-name> <%s>", COMMANDS.join("|")) o.separator '' o.on('-h', '--help', 'Print this help') do safe_puts(opts.help) end end argv = (opts) group, action = argv[0], argv[1] if !group || !action || !COMMANDS.include?(action) safe_puts(opts.help) return nil end if action == 'hosts' @env.ui.info(sprintf('Hosts in %s group:', group)) with_target_vms() do |machine| if machine.config.group.groups.has_key?(group) if machine.config.group.groups[group].to_a.include? machine.name.to_s @env.ui.info(sprintf(' - %s', machine.name)) end elsif @env.ui.warn('No hosts associated.') break end end elsif with_target_vms() do |machine| if machine.config.group.groups.has_key?(group) if machine.config.group.groups[group].include? machine.name.to_s machine.action(action) end end end end end |