diff --git a/lib/vagrant.rb b/lib/vagrant.rb index 33164a07e..f8ff8694f 100644 --- a/lib/vagrant.rb +++ b/lib/vagrant.rb @@ -102,6 +102,7 @@ Vagrant.commands.register(:reload) { Vagrant::Command::Reload } Vagrant.commands.register(:resume) { Vagrant::Command::Resume } Vagrant.commands.register(:ssh) { Vagrant::Command::SSH } Vagrant.commands.register(:"ssh-config") { Vagrant::Command::SSHConfig } +Vagrant.commands.register(:status) { Vagrant::Command::Status } Vagrant.commands.register(:suspend) { Vagrant::Command::Suspend } Vagrant.commands.register(:up) { Vagrant::Command::Up } diff --git a/lib/vagrant/command.rb b/lib/vagrant/command.rb index cc2a21c96..cfabf9df6 100644 --- a/lib/vagrant/command.rb +++ b/lib/vagrant/command.rb @@ -10,6 +10,7 @@ module Vagrant autoload :Resume, 'vagrant/command/resume' autoload :SSH, 'vagrant/command/ssh' autoload :SSHConfig, 'vagrant/command/ssh_config' + autoload :Status, 'vagrant/command/status' autoload :Suspend, 'vagrant/command/suspend' autoload :Up, 'vagrant/command/up' end diff --git a/lib/vagrant/command/status.rb b/lib/vagrant/command/status.rb index 6d2520c07..346c7ad95 100644 --- a/lib/vagrant/command/status.rb +++ b/lib/vagrant/command/status.rb @@ -1,11 +1,22 @@ +require 'optparse' + module Vagrant module Command - class StatusCommand < NamedBase - register "status", "Shows the status of the current Vagrant environment." - + class Status < Base def execute + options = {} + + opts = OptionParser.new do |opts| + opts.banner = "Usage: vagrant status [vm-name]" + end + + # Parse the options + argv = parse_options(opts) + return if !argv + state = nil - results = target_vms.collect do |vm| + results = [] + with_target_vms(argv[0]) do |vm| if vm.created? if vm.vm.accessible? state = vm.vm.state.to_s @@ -16,15 +27,15 @@ module Vagrant state = "not_created" end - "#{vm.name.to_s.ljust(25)}#{state.gsub("_", " ")}" + results << "#{vm.name.to_s.ljust(25)}#{state.gsub("_", " ")}" end - state = target_vms.length == 1 ? state : "listing" + state = results.length == 1 ? state : "listing" - env.ui.info(I18n.t("vagrant.commands.status.output", - :states => results.join("\n"), - :message => I18n.t("vagrant.commands.status.#{state}")), - :prefix => false) + @env.ui.info(I18n.t("vagrant.commands.status.output", + :states => results.join("\n"), + :message => I18n.t("vagrant.commands.status.#{state}")), + :prefix => false) end end end