diff --git a/lib/vagrant.rb b/lib/vagrant.rb index 82e5b9e68..9bfb557e9 100644 --- a/lib/vagrant.rb +++ b/lib/vagrant.rb @@ -13,6 +13,7 @@ module Vagrant autoload :Base, 'vagrant/command/base' autoload :GroupBase, 'vagrant/command/group_base' autoload :Helpers, 'vagrant/command/helpers' + autoload :NamedBase, 'vagrant/command/named_base' end # The source root is the path to the root directory of diff --git a/lib/vagrant/command/destroy.rb b/lib/vagrant/command/destroy.rb index 3a68eb301..e8c973d8f 100644 --- a/lib/vagrant/command/destroy.rb +++ b/lib/vagrant/command/destroy.rb @@ -1,6 +1,6 @@ module Vagrant module Command - class DestroyCommand < Base + class DestroyCommand < NamedBase desc "Destroy the environment, deleting the created virtual machines" register "destroy" diff --git a/lib/vagrant/command/halt.rb b/lib/vagrant/command/halt.rb index a1df59a4b..64d291799 100644 --- a/lib/vagrant/command/halt.rb +++ b/lib/vagrant/command/halt.rb @@ -1,6 +1,6 @@ module Vagrant module Command - class HaltCommand < Base + class HaltCommand < NamedBase desc "Halt the running VMs in the environment" class_option :force, :type => :boolean, :default => false, :aliases => "-f" register "halt" diff --git a/lib/vagrant/command/named_base.rb b/lib/vagrant/command/named_base.rb new file mode 100644 index 000000000..0608da6d0 --- /dev/null +++ b/lib/vagrant/command/named_base.rb @@ -0,0 +1,9 @@ +module Vagrant + module Command + # Same as {Base} except adds the `name` argument so that you + # can use methods such as `target_vms` in your command. + class NamedBase < Base + argument :name, :type => :string, :optional => true + end + end +end diff --git a/lib/vagrant/command/package.rb b/lib/vagrant/command/package.rb index 2854086b1..a1da93b8a 100644 --- a/lib/vagrant/command/package.rb +++ b/lib/vagrant/command/package.rb @@ -1,6 +1,6 @@ module Vagrant module Command - class PackageCommand < Base + class PackageCommand < NamedBase desc "Package a Vagrant environment for distribution" class_option :base, :type => :string, :default => nil class_option :output, :type => :string, :default => nil diff --git a/lib/vagrant/command/provision.rb b/lib/vagrant/command/provision.rb index 2f4a999ea..9cd286ffb 100644 --- a/lib/vagrant/command/provision.rb +++ b/lib/vagrant/command/provision.rb @@ -1,6 +1,6 @@ module Vagrant module Command - class ProvisionCommand < Base + class ProvisionCommand < NamedBase desc "Rerun the provisioning scripts on a running VM" register "provision" diff --git a/lib/vagrant/command/reload.rb b/lib/vagrant/command/reload.rb index fdcf00fbc..4b7c83194 100644 --- a/lib/vagrant/command/reload.rb +++ b/lib/vagrant/command/reload.rb @@ -1,6 +1,6 @@ module Vagrant module Command - class ReloadCommand < Base + class ReloadCommand < NamedBase desc "Reload the environment, halting it then restarting it." register "reload" diff --git a/lib/vagrant/command/resume.rb b/lib/vagrant/command/resume.rb index 444c9b5fa..1c1cdf6e3 100644 --- a/lib/vagrant/command/resume.rb +++ b/lib/vagrant/command/resume.rb @@ -1,6 +1,6 @@ module Vagrant module Command - class ResumeCommand < Base + class ResumeCommand < NamedBase desc "Resume a suspended Vagrant environment." register "resume" diff --git a/lib/vagrant/command/ssh.rb b/lib/vagrant/command/ssh.rb index b8b1f2303..c4859fb27 100644 --- a/lib/vagrant/command/ssh.rb +++ b/lib/vagrant/command/ssh.rb @@ -1,6 +1,6 @@ module Vagrant module Command - class SSHCommand < Base + class SSHCommand < NamedBase desc "SSH into the currently running Vagrant environment." class_option :execute, :type => :string, :default => false, :aliases => "-e" register "ssh" @@ -31,7 +31,7 @@ module Vagrant def ssh_vm @ssh_vm ||= begin - vm = self.name.nil? && env.multivm? ? env.primary_vm + vm = self.name.nil? && env.multivm? ? env.primary_vm : nil raise MultiVMTargetRequired.new("A target or primary VM must be specified for SSH in a multi-vm environment.") if !vm && target_vms.length > 1 vm = target_vms.first if !vm vm diff --git a/lib/vagrant/command/up.rb b/lib/vagrant/command/up.rb index 7801b94c1..1522e6191 100644 --- a/lib/vagrant/command/up.rb +++ b/lib/vagrant/command/up.rb @@ -1,14 +1,12 @@ module Vagrant module Command - class UpCommand < Base + class UpCommand < NamedBase desc "Creates the Vagrant environment" - argument :name, :type => :string, :optional => true class_option :provision, :type => :boolean, :default => true register "up" def execute # TODO: Make the options[:provision] actually mean something - target_vms.each do |vm| if vm.created? vm.env.ui.info "VM already created. Booting if its not already running..."