From af1b098b9d2eb220f1494fdc2b7f7121202e9e81 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 1 May 2010 00:24:39 -0700 Subject: [PATCH] `vagrant status --global` flag to view global status --- lib/vagrant/commands/status.rb | 42 ++++++++++++++++++++++++++-- templates/strings.yml | 10 +++++++ test/vagrant/commands/status_test.rb | 12 +++++++- vagrant.gemspec | 2 +- 4 files changed, 62 insertions(+), 4 deletions(-) diff --git a/lib/vagrant/commands/status.rb b/lib/vagrant/commands/status.rb index 70ce6bc47..bcf4dde12 100644 --- a/lib/vagrant/commands/status.rb +++ b/lib/vagrant/commands/status.rb @@ -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 diff --git a/templates/strings.yml b/templates/strings.yml index 00b12fcf8..7cac40e82 100644 --- a/templates/strings.yml +++ b/templates/strings.yml @@ -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 diff --git a/test/vagrant/commands/status_test.rb b/test/vagrant/commands/status_test.rb index 1cdffca78..f975d5885 100644 --- a/test/vagrant/commands/status_test.rb +++ b/test/vagrant/commands/status_test.rb @@ -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 diff --git a/vagrant.gemspec b/vagrant.gemspec index 4f0734992..fd2fd4d2f 100644 --- a/vagrant.gemspec +++ b/vagrant.gemspec @@ -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"]