`vagrant status`

This commit is contained in:
Mitchell Hashimoto 2011-12-17 17:36:11 -08:00
parent 1176c65138
commit 780722386b
3 changed files with 23 additions and 10 deletions

View File

@ -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 }

View File

@ -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

View File

@ -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,12 +27,12 @@ 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",
@env.ui.info(I18n.t("vagrant.commands.status.output",
:states => results.join("\n"),
:message => I18n.t("vagrant.commands.status.#{state}")),
:prefix => false)