From 59d398c4051ade7af165e5e94d76201838492799 Mon Sep 17 00:00:00 2001 From: Nandor Kiss Date: Wed, 16 Sep 2020 22:25:41 +0200 Subject: [PATCH 1/2] --yes at vagrant cloud version release command. --- plugins/commands/cloud/version/release.rb | 12 +++++-- .../commands/cloud/version/release_test.rb | 31 +++++++++++++++++-- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/plugins/commands/cloud/version/release.rb b/plugins/commands/cloud/version/release.rb index db0b612b0..073e83f5b 100644 --- a/plugins/commands/cloud/version/release.rb +++ b/plugins/commands/cloud/version/release.rb @@ -18,6 +18,10 @@ module VagrantPlugins o.on("-u", "--username USERNAME_OR_EMAIL", String, "Vagrant Cloud username or email address") do |u| options[:username] = u end + options[:assume_yes] = false + o.on("-y", "--yes", "Automatic yes to prompts") do |y| + options[:assume_yes] = y + end end # Parse the options @@ -28,9 +32,11 @@ module VagrantPlugins help: opts.help.chomp end - @env.ui.warn(I18n.t("cloud_command.version.release_warn", version: argv[1], box: argv.first)) - cont = @env.ui.ask(I18n.t("cloud_command.continue")) - return 1 if cont.strip.downcase != "y" + if not options[:assume_yes] + @env.ui.warn(I18n.t("cloud_command.version.release_warn", version: argv[1], box: argv.first)) + cont = @env.ui.ask(I18n.t("cloud_command.continue")) + return 1 if cont.strip.downcase != "y" + end @client = VagrantPlugins::CloudCommand::Util.client_login(@env, options[:username]) box = argv.first.split('/', 2) diff --git a/test/unit/plugins/commands/cloud/version/release_test.rb b/test/unit/plugins/commands/cloud/version/release_test.rb index bc5ddc131..fde68cd4b 100644 --- a/test/unit/plugins/commands/cloud/version/release_test.rb +++ b/test/unit/plugins/commands/cloud/version/release_test.rb @@ -30,8 +30,6 @@ describe VagrantPlugins::CloudCommand::VersionCommand::Command::Release do allow(VagrantCloud::Box).to receive(:new) .with(anything, "box-name", nil, nil, nil, client.token) .and_return(box) - allow(iso_env.ui).to receive(:ask). - and_return("y") end context "with no arguments" do @@ -41,9 +39,36 @@ describe VagrantPlugins::CloudCommand::VersionCommand::Command::Release do end end - context "with arguments" do + context "interactive mode with arguments" do let (:argv) { ["vagrant/box-name", "1.0.0"] } + it "releases a version" do + allow(iso_env.ui).to receive(:ask). + and_return("y") + allow(VagrantCloud::Version).to receive(:new). + with(box, "1.0.0", nil, nil, client.token). + and_return(version) + + expect(version).to receive(:release).and_return({}) + expect(subject.execute).to eq(0) + end + + it "displays an error if encoutering a problem with the request" do + allow(iso_env.ui).to receive(:ask). + and_return("y") + allow(VagrantCloud::Version).to receive(:new). + with(box, "1.0.0", nil, nil, client.token). + and_return(version) + + allow(version).to receive(:release). + and_raise(VagrantCloud::ClientError.new("Fail Message", "Message", 404)) + expect(subject.execute).to eq(1) + end + end + + context "non-interactive mode with arguments" do + let (:argv) { ["--yes", "vagrant/box-name", "1.0.0"] } + it "releases a version" do allow(VagrantCloud::Version).to receive(:new). with(box, "1.0.0", nil, nil, client.token). From cc3cdfe45222a61c47c5a4fb74bcca024ad3eb8a Mon Sep 17 00:00:00 2001 From: Nandor Kiss Date: Tue, 22 Sep 2020 20:13:30 +0200 Subject: [PATCH 2/2] --force instead of --yes. --- plugins/commands/cloud/version/release.rb | 8 ++++---- test/unit/plugins/commands/cloud/version/release_test.rb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/commands/cloud/version/release.rb b/plugins/commands/cloud/version/release.rb index 073e83f5b..eb7c16a73 100644 --- a/plugins/commands/cloud/version/release.rb +++ b/plugins/commands/cloud/version/release.rb @@ -18,9 +18,9 @@ module VagrantPlugins o.on("-u", "--username USERNAME_OR_EMAIL", String, "Vagrant Cloud username or email address") do |u| options[:username] = u end - options[:assume_yes] = false - o.on("-y", "--yes", "Automatic yes to prompts") do |y| - options[:assume_yes] = y + options[:force] = false + o.on("-f", "--force", "Release without confirmation") do |f| + options[:force] = f end end @@ -32,7 +32,7 @@ module VagrantPlugins help: opts.help.chomp end - if not options[:assume_yes] + if not options[:force] @env.ui.warn(I18n.t("cloud_command.version.release_warn", version: argv[1], box: argv.first)) cont = @env.ui.ask(I18n.t("cloud_command.continue")) return 1 if cont.strip.downcase != "y" diff --git a/test/unit/plugins/commands/cloud/version/release_test.rb b/test/unit/plugins/commands/cloud/version/release_test.rb index fde68cd4b..ac8f75c4e 100644 --- a/test/unit/plugins/commands/cloud/version/release_test.rb +++ b/test/unit/plugins/commands/cloud/version/release_test.rb @@ -67,7 +67,7 @@ describe VagrantPlugins::CloudCommand::VersionCommand::Command::Release do end context "non-interactive mode with arguments" do - let (:argv) { ["--yes", "vagrant/box-name", "1.0.0"] } + let (:argv) { ["--force", "vagrant/box-name", "1.0.0"] } it "releases a version" do allow(VagrantCloud::Version).to receive(:new).