2023-08-10 16:53:25 -04:00
|
|
|
# Copyright (c) HashiCorp, Inc.
|
|
|
|
|
# SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
|
2012-04-19 16:59:48 -04:00
|
|
|
require 'optparse'
|
|
|
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
|
module CommandBox
|
|
|
|
|
module Command
|
2013-10-16 09:58:11 -04:00
|
|
|
class Remove < Vagrant.plugin("2", :command)
|
2012-04-19 16:59:48 -04:00
|
|
|
def execute
|
2014-01-23 23:51:00 -05:00
|
|
|
options = {}
|
2014-04-23 09:16:51 -04:00
|
|
|
options[:force] = false
|
|
|
|
|
|
2013-02-02 19:43:16 -05:00
|
|
|
opts = OptionParser.new do |o|
|
2014-01-23 23:51:00 -05:00
|
|
|
o.banner = "Usage: vagrant box remove <name>"
|
|
|
|
|
o.separator ""
|
2014-02-08 03:20:50 -05:00
|
|
|
o.separator "Options:"
|
2014-04-23 09:16:51 -04:00
|
|
|
o.separator ""
|
|
|
|
|
|
2016-06-08 08:05:09 -04:00
|
|
|
o.on("-f", "--force", "Remove without confirmation.") do |f|
|
2014-04-23 09:16:51 -04:00
|
|
|
options[:force] = f
|
|
|
|
|
end
|
2014-01-23 23:51:00 -05:00
|
|
|
|
2023-07-28 13:40:02 -04:00
|
|
|
o.on("-a", "--architecture ARCH", String, "The specific architecture for the box to remove") do |a|
|
|
|
|
|
options[:architecture] = a
|
|
|
|
|
end
|
2014-02-08 03:20:50 -05:00
|
|
|
o.on("--provider PROVIDER", String,
|
|
|
|
|
"The specific provider type for the box to remove") do |p|
|
2014-01-23 23:51:00 -05:00
|
|
|
options[:provider] = p
|
|
|
|
|
end
|
|
|
|
|
|
2014-02-08 03:20:50 -05:00
|
|
|
o.on("--box-version VERSION", String,
|
|
|
|
|
"The specific version of the box to remove") do |v|
|
2014-01-23 23:51:00 -05:00
|
|
|
options[:version] = v
|
|
|
|
|
end
|
2014-04-13 06:24:22 -04:00
|
|
|
|
|
|
|
|
o.on("--all", "Remove all available versions of the box") do |a|
|
|
|
|
|
options[:all] = a
|
|
|
|
|
end
|
2023-07-28 13:40:02 -04:00
|
|
|
|
|
|
|
|
o.on("--all-providers", "Remove all providers within a version of the box") do |a|
|
|
|
|
|
options[:all_providers] = a
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
o.on("--all-architectures", "Remove all architectures within a provider a version of the box") do |a|
|
|
|
|
|
options[:all_architectures] = a
|
|
|
|
|
end
|
2012-04-19 16:59:48 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Parse the options
|
|
|
|
|
argv = parse_options(opts)
|
|
|
|
|
return if !argv
|
2014-01-23 23:51:00 -05:00
|
|
|
if argv.empty? || argv.length > 2
|
|
|
|
|
raise Vagrant::Errors::CLIInvalidUsage,
|
|
|
|
|
help: opts.help.chomp
|
|
|
|
|
end
|
2013-07-10 22:57:53 -04:00
|
|
|
|
2014-01-23 23:51:00 -05:00
|
|
|
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]
|
2013-07-10 22:57:53 -04:00
|
|
|
end
|
2012-04-19 16:59:48 -04:00
|
|
|
|
2013-10-16 09:58:11 -04:00
|
|
|
@env.action_runner.run(Vagrant::Action.action_box_remove, {
|
2014-05-22 12:35:12 -04:00
|
|
|
box_name: argv[0],
|
2023-07-28 13:40:02 -04:00
|
|
|
box_architecture: options[:architecture],
|
2014-05-22 12:35:12 -04:00
|
|
|
box_provider: options[:provider],
|
|
|
|
|
box_version: options[:version],
|
|
|
|
|
force_confirm_box_remove: options[:force],
|
2014-04-13 06:24:22 -04:00
|
|
|
box_remove_all_versions: options[:all],
|
2023-07-28 13:40:02 -04:00
|
|
|
box_remove_all_providers: options[:all_providers],
|
|
|
|
|
box_remove_all_architectures: options[:all_architectures]
|
2013-10-04 20:54:21 -04:00
|
|
|
})
|
2012-04-19 16:59:48 -04:00
|
|
|
|
|
|
|
|
# Success, exit status 0
|
|
|
|
|
0
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|