`vagrant halt`

This commit is contained in:
Mitchell Hashimoto 2011-12-17 11:14:56 -08:00
parent 7a76fd7e05
commit 6c7e88c3ec
3 changed files with 27 additions and 7 deletions

View File

@ -95,6 +95,7 @@ I18n.load_path << File.expand_path("templates/locales/en.yml", Vagrant.source_ro
# Register the built-in commands # Register the built-in commands
Vagrant.commands.register(:destroy) { Vagrant::Command::Destroy } Vagrant.commands.register(:destroy) { Vagrant::Command::Destroy }
Vagrant.commands.register(:halt) { Vagrant::Command::Halt }
Vagrant.commands.register(:up) { Vagrant::Command::Up } Vagrant.commands.register(:up) { Vagrant::Command::Up }
# Register the built-in config keys # Register the built-in config keys

View File

@ -3,6 +3,7 @@ module Vagrant
autoload :Base, 'vagrant/command/base' autoload :Base, 'vagrant/command/base'
autoload :Destroy, 'vagrant/command/destroy' autoload :Destroy, 'vagrant/command/destroy'
autoload :Halt, 'vagrant/command/halt'
autoload :Up, 'vagrant/command/up' autoload :Up, 'vagrant/command/up'
end end
end end

View File

@ -1,15 +1,33 @@
require 'optparse'
module Vagrant module Vagrant
module Command module Command
class HaltCommand < NamedBase class Halt < Base
class_option :force, :type => :boolean, :default => false, :aliases => "-f"
register "halt", "Halt the running VMs in the environment"
def execute def execute
target_vms.each do |vm| options = {}
opts = OptionParser.new do |opts|
opts.banner = "Usage: vagrant halt [vm-name] [--force] [-h]"
opts.separator ""
opts.on("-f", "--force", "Force shut down (equivalent of pulling power)") do |f|
options[:force] = f
end
end
# Parse the options
argv = parse_options(opts)
return if !argv
@logger.debug("Halt command: #{argv.inspect} #{options.inspect}")
with_target_vms(argv[0]) do |vm|
if vm.created? if vm.created?
vm.halt(options) @logger.info("Halting #{vm.name}")
vm.halt(:force => options[:force])
else else
vm.env.ui.info I18n.t("vagrant.commands.common.vm_not_created") @logger.info("Not halting #{vm.name}, since not created.")
vm.ui.info I18n.t("vagrant.commands.common.vm_not_created")
end end
end end
end end