vagrant/plugins/commands/box/command/remove.rb

62 lines
1.8 KiB
Ruby
Raw Normal View History

2012-04-19 20:59:48 +00:00
require 'optparse'
module VagrantPlugins
module CommandBox
module Command
class Remove < Vagrant.plugin("2", :command)
2012-04-19 20:59:48 +00:00
def execute
options = {}
2014-04-23 13:16:51 +00:00
options[:force] = false
opts = OptionParser.new do |o|
o.banner = "Usage: vagrant box remove <name>"
o.separator ""
2014-02-08 08:20:50 +00:00
o.separator "Options:"
2014-04-23 13:16:51 +00:00
o.separator ""
o.on("-f", "--force", "Destroy without confirmation.") do |f|
options[:force] = f
end
2014-02-08 08:20:50 +00:00
o.on("--provider PROVIDER", String,
"The specific provider type for the box to remove") do |p|
options[:provider] = p
end
2014-02-08 08:20:50 +00:00
o.on("--box-version VERSION", String,
"The specific version of the box to remove") do |v|
options[:version] = v
end
2012-04-19 20:59:48 +00:00
end
# Parse the options
argv = parse_options(opts)
return if !argv
if argv.empty? || argv.length > 2
raise Vagrant::Errors::CLIInvalidUsage,
help: opts.help.chomp
end
if argv.length == 2
# @deprecated
@env.ui.warn("WARNING: The second argument to `vagrant box remove`")
@env.ui.warn("is deprecated. Please use the --provider flag. This")
@env.ui.warn("feature will stop working in the next version.")
options[:provider] = argv[1]
end
2012-04-19 20:59:48 +00:00
@env.action_runner.run(Vagrant::Action.action_box_remove, {
box_name: argv[0],
box_provider: options[:provider],
box_version: options[:version],
force_confirm_box_remove: options[:force],
})
2012-04-19 20:59:48 +00:00
# Success, exit status 0
0
end
end
end
end
end