From 5da77dee5caa9950920cd9f95a69e6b3fbcd82b7 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 23 Apr 2014 06:16:51 -0700 Subject: [PATCH] commands/box/remove: add --force flag --- plugins/commands/box/command/remove.rb | 9 ++++++++- .../plugins/commands/box/command/remove_test.rb | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/plugins/commands/box/command/remove.rb b/plugins/commands/box/command/remove.rb index f2a268121..28eed63f5 100644 --- a/plugins/commands/box/command/remove.rb +++ b/plugins/commands/box/command/remove.rb @@ -6,11 +6,17 @@ module VagrantPlugins class Remove < Vagrant.plugin("2", :command) def execute options = {} + options[:force] = false + opts = OptionParser.new do |o| o.banner = "Usage: vagrant box remove " o.separator "" o.separator "Options:" - o.separator "" + o.separator "" + + o.on("-f", "--force", "Destroy without confirmation.") do |f| + options[:force] = f + end o.on("--provider PROVIDER", String, "The specific provider type for the box to remove") do |p| @@ -43,6 +49,7 @@ module VagrantPlugins :box_name => argv[0], :box_provider => options[:provider], :box_version => options[:version], + :force_confirm_box_remove => options[:force], }) # Success, exit status 0 diff --git a/test/unit/plugins/commands/box/command/remove_test.rb b/test/unit/plugins/commands/box/command/remove_test.rb index 67c4a0131..923d920b5 100644 --- a/test/unit/plugins/commands/box/command/remove_test.rb +++ b/test/unit/plugins/commands/box/command/remove_test.rb @@ -34,11 +34,26 @@ describe VagrantPlugins::CommandBox::Command::Remove do it "invokes the action runner" do expect(action_runner).to receive(:run).with { |action, opts| expect(opts[:box_name]).to eq("foo") + expect(opts[:force_confirm_box_remove]).to be_false true } subject.execute end + + context "with --force" do + let(:argv) { super() + ["--force"] } + + it "invokes the action runner with force option" do + expect(action_runner).to receive(:run).with { |action, opts| + expect(opts[:box_name]).to eq("foo") + expect(opts[:force_confirm_box_remove]).to be_true + true + } + + subject.execute + end + end end context "with two arguments" do