`vagrant status --global` flag to view global status

This commit is contained in:
Mitchell Hashimoto 2010-05-01 00:24:39 -07:00
parent 1900d1faaa
commit af1b098b9d
4 changed files with 62 additions and 4 deletions

View File

@ -5,9 +5,23 @@ module Vagrant
# and if its running, suspended, etc.
class Status < Base
Base.subcommand "status", self
description "Shows the status of the current environment."
description "Shows the status of the Vagrant environment."
def execute(args=[])
parse_options(args)
if !options[:global]
show_local_status
else
show_global_status
end
end
# Shows the status of the CURRENT environment (the current working
# directory). This prints out a human friendly sentence or paragraph
# describing the state of the Vagrant environment represented by the
# current working directory.
def show_local_status
string_key = nil
if !env.root_path
@ -34,8 +48,32 @@ module Vagrant
wrap_output { puts Translator.t(*string_key) }
end
# Shows the status of the GLOBAL Vagrant environment. This prints out
# a listing of the virtual machines which Vagrant manages (running or
# not).
def show_global_status
entries = []
env.active_list.list.each do |uuid, data|
vm = Vagrant::VM.find(uuid, env)
entries << Translator.t(:status_global_entry, {
:vm => vm,
:data => data
})
end
wrap_output { puts Translator.t(:status_global, :entries => entries) }
end
def options_spec(opts)
opts.banner = "Usage: vagrant status"
opts.banner = "Usage: vagrant status [--global]"
# Defaults
options[:global] = false
opts.on("-g", "--global", "Show global status of Vagrant (running VMs managed by Vagrant)") do |v|
options[:global] = true
end
end
end
end

View File

@ -25,6 +25,16 @@
To resume this VM, simply run `vagrant up`.
:status_created_powered_off: |-
To restart this VM, simply run `vagrant up`.
:status_global: |-
Below is a list of virtual machines which are currently created and were
created by a Vagrant environment. The path listed was the "last known path"
of the environment (it may have moved).
<%= entries.join("\n\n") %>
:status_global_entry: |-
Name: <%= vm.vm.name %>
Path: <%= data["path"] %>
Created at: <%= Time.at(data["created_at"]) %>
#---------------------------------------------------------------------
# CATEGORY: Error Messages

View File

@ -15,6 +15,16 @@ class CommandsStatusTest < Test::Unit::TestCase
end
context "executing" do
# TODO
should "show local status by default" do
@instance.expects(:show_local_status).once
@instance.expects(:show_global_status).never
@instance.execute
end
should "show global status if flagged" do
@instance.expects(:show_local_status).never
@instance.expects(:show_global_status).once
@instance.execute(["--global"])
end
end
end

View File

@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["Mitchell Hashimoto", "John Bender"]
s.date = %q{2010-04-30}
s.date = %q{2010-05-01}
s.default_executable = %q{vagrant}
s.description = %q{Vagrant is a tool for building and distributing virtualized development environments.}
s.email = ["mitchell.hashimoto@gmail.com", "john.m.bender@gmail.com"]