commands/box/remove: update for new syntax
This commit is contained in:
parent
8ef13b037c
commit
29da748702
|
@ -5,38 +5,42 @@ module VagrantPlugins
|
|||
module Command
|
||||
class Remove < Vagrant.plugin("2", :command)
|
||||
def execute
|
||||
options = {}
|
||||
opts = OptionParser.new do |o|
|
||||
o.banner = "Usage: vagrant box remove <name> <provider>"
|
||||
o.banner = "Usage: vagrant box remove <name>"
|
||||
o.separator ""
|
||||
|
||||
o.on("--provider VALUE", String,
|
||||
"The specific provider type for the box to remove.") do |p|
|
||||
options[:provider] = p
|
||||
end
|
||||
|
||||
o.on("--version VALUE", String,
|
||||
"The specific version of the box to remove.") do |v|
|
||||
options[:version] = v
|
||||
end
|
||||
end
|
||||
|
||||
# Parse the options
|
||||
argv = parse_options(opts)
|
||||
return if !argv
|
||||
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
|
||||
if argv.empty? || argv.length > 2
|
||||
raise Vagrant::Errors::CLIInvalidUsage,
|
||||
help: opts.help.chomp
|
||||
end
|
||||
|
||||
if providers.length > 1
|
||||
@env.ui.error(
|
||||
I18n.t("vagrant.commands.box.remove_must_specify_provider",
|
||||
name: argv[0],
|
||||
providers: providers.join(", ")))
|
||||
return 1
|
||||
end
|
||||
|
||||
argv[1] = providers[0] || ""
|
||||
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
|
||||
|
||||
@env.action_runner.run(Vagrant::Action.action_box_remove, {
|
||||
:box_name => argv[0],
|
||||
:box_provider => argv[1]
|
||||
:box_provider => options[:provider],
|
||||
:box_version => options[:version],
|
||||
})
|
||||
|
||||
# Success, exit status 0
|
||||
|
|
|
@ -974,17 +974,6 @@ en:
|
|||
vm_not_created: "VM not created. Moving on..."
|
||||
vm_not_running: "VM is not currently running. Please, first bring it up with `vagrant up` then run this command."
|
||||
box:
|
||||
remove_must_specify_provider: |-
|
||||
Multiple providers were found for the box '%{name}'. Please specify
|
||||
the specific provider for the box you want to remove. The list of
|
||||
providers backing this box is:
|
||||
|
||||
'%{providers}'
|
||||
|
||||
To remove the box for a specific provider, run the following command,
|
||||
filling in PROVIDER with one of the providers above:
|
||||
|
||||
vagrant box remove '%{name}' PROVIDER
|
||||
no_installed_boxes: "There are no installed boxes! Use `vagrant box add` to add some."
|
||||
removing: |-
|
||||
Removing box '%{name}' with provider '%{provider}'...
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
require File.expand_path("../../../../../base", __FILE__)
|
||||
|
||||
require Vagrant.source_root.join("plugins/commands/box/command/remove")
|
||||
|
||||
describe VagrantPlugins::CommandBox::Command::Remove do
|
||||
include_context "unit"
|
||||
|
||||
let(:argv) { [] }
|
||||
let(:iso_env) do
|
||||
# We have to create a Vagrantfile so there is a root path
|
||||
env = isolated_environment
|
||||
env.vagrantfile("")
|
||||
env.create_vagrant_env
|
||||
end
|
||||
|
||||
subject { described_class.new(argv, iso_env) }
|
||||
|
||||
let(:action_runner) { double("action_runner") }
|
||||
|
||||
before do
|
||||
iso_env.stub(action_runner: action_runner)
|
||||
end
|
||||
|
||||
context "with no arguments" do
|
||||
it "shows help" do
|
||||
expect { subject.execute }.
|
||||
to raise_error(Vagrant::Errors::CLIInvalidUsage)
|
||||
end
|
||||
end
|
||||
|
||||
context "with one argument" do
|
||||
let(:argv) { ["foo"] }
|
||||
|
||||
it "invokes the action runner" do
|
||||
action_runner.should_receive(:run).with do |action, opts|
|
||||
expect(opts[:box_name]).to eq("foo")
|
||||
true
|
||||
end
|
||||
|
||||
subject.execute
|
||||
end
|
||||
end
|
||||
|
||||
context "with two arguments" do
|
||||
let(:argv) { ["foo", "bar"] }
|
||||
|
||||
it "uses the 2nd arg as a provider" do
|
||||
action_runner.should_receive(:run).with do |action, opts|
|
||||
expect(opts[:box_name]).to eq("foo")
|
||||
expect(opts[:box_provider]).to eq("bar")
|
||||
true
|
||||
end
|
||||
|
||||
subject.execute
|
||||
end
|
||||
end
|
||||
|
||||
context "with more than two arguments" do
|
||||
let(:argv) { ["one", "two", "three"] }
|
||||
|
||||
it "shows help" do
|
||||
expect { subject.execute }.
|
||||
to raise_error(Vagrant::Errors::CLIInvalidUsage)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue