vagrant/plugins/commands/halt/command.rb

34 lines
808 B
Ruby
Raw Normal View History

2011-12-17 19:14:56 +00:00
require 'optparse'
2012-04-19 20:59:48 +00:00
module VagrantPlugins
module CommandHalt
2012-11-07 05:05:14 +00:00
class Command < Vagrant.plugin("2", :command)
2010-08-25 06:10:58 +00:00
def execute
2011-12-17 19:14:56 +00:00
options = {}
2013-01-29 18:55:40 +00:00
options[:force] = false
2011-12-17 19:14:56 +00:00
2013-01-29 18:55:40 +00:00
opts = OptionParser.new do |o|
o.banner = "Usage: vagrant halt [vm-name] [--force] [-h]"
o.separator ""
2011-12-17 19:14:56 +00:00
2013-01-29 18:55:40 +00:00
o.on("-f", "--force", "Force shut down (equivalent of pulling power)") do |f|
2011-12-17 19:14:56 +00:00
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) do |vm|
2013-01-29 18:55:40 +00:00
vm.action(:halt, :force_halt => options[:force])
2010-08-25 06:10:58 +00:00
end
# Success, exit status 0
0
2013-01-29 18:55:40 +00:00
end
2010-08-25 06:10:58 +00:00
end
end
end