A very basic `vagrant status` command, which simply outputs the status of the environment (whether it has been created, its on, its off, etc.)
This commit is contained in:
parent
f6057bf80a
commit
42007f6b80
|
@ -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
|
|
@ -24,6 +24,49 @@ error
|
||||||
FileUtils.cp(File.join(PROJECT_ROOT, "templates", Env::ROOTFILE_NAME), rootfile_path)
|
FileUtils.cp(File.join(PROJECT_ROOT, "templates", Env::ROOTFILE_NAME), rootfile_path)
|
||||||
end
|
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
|
# Bring up a vagrant instance. This handles everything from importing
|
||||||
# the base VM, setting up shared folders, forwarded ports, etc to
|
# the base VM, setting up shared folders, forwarded ports, etc to
|
||||||
# provisioning the instance with chef. {up} also starts the instance,
|
# provisioning the instance with chef. {up} also starts the instance,
|
||||||
|
|
Loading…
Reference in New Issue