diff --git a/bin/vagrant-status b/bin/vagrant-status new file mode 100755 index 000000000..2e4f0d461 --- /dev/null +++ b/bin/vagrant-status @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +begin + require File.expand_path('../../.bundle/environment', __FILE__) +rescue LoadError + # Fallback on rubygems + require "rubygems" +end + +require 'git-style-binary/command' + +# Get library +libdir = File.join(File.dirname(__FILE__), '..', 'lib') +require File.expand_path('vagrant', libdir) + +GitStyleBinary.command do + short_desc "Outputs the status of the current environment" + banner <<-EOS +Usage: #{command.full_name} #{all_options_string} + +This command outputs the status of the current environment. This command +tells you whether the environment is created, running, suspended, +etc. + +EOS + + run do |command| + Vagrant::Commands.status + end +end diff --git a/lib/vagrant/commands.rb b/lib/vagrant/commands.rb index 4f140df66..044dc96cf 100644 --- a/lib/vagrant/commands.rb +++ b/lib/vagrant/commands.rb @@ -24,6 +24,49 @@ error FileUtils.cp(File.join(PROJECT_ROOT, "templates", Env::ROOTFILE_NAME), rootfile_path) end + # Outputs the status of the current environment. This command outputs + # useful information such as whether or not the environment is created + # and if its running, suspended, etc. + def status + Env.load! + + wrap_output do + if !Env.persisted_vm + puts <<-msg +The environment has not yet been created. Run `vagrant up` to create the +environment. +msg + else + additional_msg = "" + if Env.persisted_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.persisted_vm.vm.saved? + additional_msg = <<-msg +To resume this VM, simply run `vagrant up`. +msg + elsif Env.persisted_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.persisted_vm.vm.state}."#{additional_msg} +msg + end + end + end + # Bring up a vagrant instance. This handles everything from importing # the base VM, setting up shared folders, forwarded ports, etc to # provisioning the instance with chef. {up} also starts the instance,