`vagrant destroy`
This commit is contained in:
parent
b292008f3b
commit
e71007d47e
|
@ -94,6 +94,7 @@ end
|
||||||
I18n.load_path << File.expand_path("templates/locales/en.yml", Vagrant.source_root)
|
I18n.load_path << File.expand_path("templates/locales/en.yml", Vagrant.source_root)
|
||||||
|
|
||||||
# Register the built-in commands
|
# Register the built-in commands
|
||||||
|
Vagrant.commands.register(:destroy) { Vagrant::Command::Destroy }
|
||||||
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
|
||||||
|
|
|
@ -2,6 +2,7 @@ module Vagrant
|
||||||
module Command
|
module Command
|
||||||
autoload :Base, 'vagrant/command/base'
|
autoload :Base, 'vagrant/command/base'
|
||||||
|
|
||||||
|
autoload :Destroy, 'vagrant/command/destroy'
|
||||||
autoload :Up, 'vagrant/command/up'
|
autoload :Up, 'vagrant/command/up'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -31,11 +31,14 @@ module Vagrant
|
||||||
#
|
#
|
||||||
# If this method returns `nil`, then you should assume that help
|
# If this method returns `nil`, then you should assume that help
|
||||||
# was printed and parsing failed.
|
# was printed and parsing failed.
|
||||||
def parse_options(opts)
|
def parse_options(opts=nil)
|
||||||
# Creating a shallow copy of the arguments so the OptionParser
|
# Creating a shallow copy of the arguments so the OptionParser
|
||||||
# doesn't destroy the originals.
|
# doesn't destroy the originals.
|
||||||
argv = @argv.dup
|
argv = @argv.dup
|
||||||
|
|
||||||
|
# Default opts to a blank optionparser if none is given
|
||||||
|
opts ||= OptionParser.new
|
||||||
|
|
||||||
# Add the help option, which must be on every command.
|
# Add the help option, which must be on every command.
|
||||||
opts.on_tail("-h", "--help", "Print this help") do
|
opts.on_tail("-h", "--help", "Print this help") do
|
||||||
puts opts.help
|
puts opts.help
|
||||||
|
|
|
@ -1,13 +1,24 @@
|
||||||
|
require 'optparse'
|
||||||
|
|
||||||
module Vagrant
|
module Vagrant
|
||||||
module Command
|
module Command
|
||||||
class DestroyCommand < NamedBase
|
class Destroy < Base
|
||||||
register "destroy", "Destroy the environment, deleting the created virtual machines"
|
|
||||||
|
|
||||||
def execute
|
def execute
|
||||||
target_vms.each do |vm|
|
opts = OptionParser.new do |opts|
|
||||||
|
opts.banner = "Usage: vagrant destroy [vm-name]"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Parse the options
|
||||||
|
argv = parse_options(opts)
|
||||||
|
return if !argv
|
||||||
|
|
||||||
|
@logger.debug("'Destroy' each target VM...")
|
||||||
|
with_target_vms(argv[0]) do |vm|
|
||||||
if vm.created?
|
if vm.created?
|
||||||
|
@logger.info("Destroying: #{vm.name}")
|
||||||
vm.destroy
|
vm.destroy
|
||||||
else
|
else
|
||||||
|
@logger.info("Not destroying #{vm.name}, since it isn't created.")
|
||||||
vm.env.ui.info I18n.t("vagrant.commands.common.vm_not_created")
|
vm.env.ui.info I18n.t("vagrant.commands.common.vm_not_created")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -25,6 +25,11 @@ describe Vagrant::Command::Base do
|
||||||
result.should == ["foo"]
|
result.should == ["foo"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "creates an option parser if none is given" do
|
||||||
|
result = klass.new(["foo"], nil).parse_options(nil)
|
||||||
|
result.should == ["foo"]
|
||||||
|
end
|
||||||
|
|
||||||
["-h", "--help"].each do |help_string|
|
["-h", "--help"].each do |help_string|
|
||||||
it "returns nil and prints the help if '#{help_string}' is given" do
|
it "returns nil and prints the help if '#{help_string}' is given" do
|
||||||
instance = klass.new([help_string], nil)
|
instance = klass.new([help_string], nil)
|
||||||
|
|
Loading…
Reference in New Issue