2012-04-19 20:59:48 +00:00
|
|
|
require 'optparse'
|
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module CommandBox
|
|
|
|
module Command
|
2012-11-07 05:05:14 +00:00
|
|
|
class Remove < Vagrant.plugin("2", :command)
|
2012-04-19 20:59:48 +00:00
|
|
|
def execute
|
2013-02-03 00:43:16 +00:00
|
|
|
opts = OptionParser.new do |o|
|
|
|
|
o.banner = "Usage: vagrant box remove <name> <provider>"
|
2012-04-19 20:59:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Parse the options
|
|
|
|
argv = parse_options(opts)
|
|
|
|
return if !argv
|
2013-07-11 02:57:53 +00:00
|
|
|
raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length < 1
|
|
|
|
|
|
|
|
if !argv[1]
|
|
|
|
# Try to automatically determine the provider.
|
|
|
|
providers = []
|
|
|
|
@env.boxes.all.each do |name, provider|
|
|
|
|
if name == argv[0]
|
|
|
|
providers << provider
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if providers.length > 1
|
|
|
|
@env.ui.error(
|
|
|
|
I18n.t("vagrant.commands.box.remove_must_specify_provider",
|
2013-08-30 16:43:35 +00:00
|
|
|
name: argv[0],
|
2013-07-11 02:57:53 +00:00
|
|
|
providers: providers.join(", ")))
|
|
|
|
return 1
|
|
|
|
end
|
|
|
|
|
|
|
|
argv[1] = providers[0] || ""
|
|
|
|
end
|
2012-04-19 20:59:48 +00:00
|
|
|
|
2013-10-05 00:54:21 +00:00
|
|
|
@env.action_runner.run(Vagrant::Action.action_box_remove, {
|
|
|
|
:box_name => argv[0],
|
|
|
|
:box_provider => argv[1],
|
|
|
|
:box_state_file => StateFile.new(@env.home_path.join('boxes.json'))
|
|
|
|
})
|
2012-04-19 20:59:48 +00:00
|
|
|
|
|
|
|
# Success, exit status 0
|
|
|
|
0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|