From 3107fa763f1334733dc0b747c9feade7ad5e916e Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 13 Apr 2010 17:02:43 -0700 Subject: [PATCH] Status command --- lib/vagrant/commands/status.rb | 53 ++++++++++++++++++++++++++++ test/vagrant/commands/status_test.rb | 20 +++++++++++ 2 files changed, 73 insertions(+) create mode 100644 lib/vagrant/commands/status.rb create mode 100644 test/vagrant/commands/status_test.rb diff --git a/lib/vagrant/commands/status.rb b/lib/vagrant/commands/status.rb new file mode 100644 index 000000000..e08470dd3 --- /dev/null +++ b/lib/vagrant/commands/status.rb @@ -0,0 +1,53 @@ +module Vagrant + class Commands + # Export and package the current vm + # + # This command requires that an instance be powered off + class Status < Base + Base.subcommand "status", self + description "Shows the status of the current environment." + + def execute(args=[]) + wrap_output do + if !env.vm + puts <<-msg +The environment has not yet been created. Run `vagrant up` to create the +environment. +msg + else + additional_msg = "" + if env.vm.vm.running? + additional_msg = <<-msg +To stop this VM, you can run `vagrant halt` to shut it down forcefully, +or you can run `vagrant suspend` to simply suspend the virtual machine. +In either case, to restart it again, simply run a `vagrant up`. +msg + elsif env.vm.vm.saved? + additional_msg = <<-msg +To resume this VM, simply run `vagrant up`. +msg + elsif env.vm.vm.powered_off? + additional_msg = <<-msg +To restart this VM, simply run `vagrant up`. +msg + end + + if !additional_msg.empty? + additional_msg.chomp! + additional_msg = "\n\n#{additional_msg}" + end + + puts <<-msg +The environment has been created. The status of the current environment's +virtual machine is: "#{env.vm.vm.state}."#{additional_msg} +msg + end + end + end + + def options_spec(opts) + opts.banner = "Usage: vagrant status" + end + end + end +end \ No newline at end of file diff --git a/test/vagrant/commands/status_test.rb b/test/vagrant/commands/status_test.rb new file mode 100644 index 000000000..1cdffca78 --- /dev/null +++ b/test/vagrant/commands/status_test.rb @@ -0,0 +1,20 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') + +class CommandsStatusTest < Test::Unit::TestCase + setup do + @klass = Vagrant::Commands::Status + + @persisted_vm = mock("persisted_vm") + @persisted_vm.stubs(:execute!) + + @env = mock_environment + @env.stubs(:require_persisted_vm) + @env.stubs(:vm).returns(@persisted_vm) + + @instance = @klass.new(@env) + end + + context "executing" do + # TODO + end +end