From 5ca382727d9f880e2b24a467e93f3ce4259bcae5 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Fri, 11 May 2018 15:43:14 -0700 Subject: [PATCH] Raise error if argument is provided with `--all-global` flag This commit raises an error if additional arguments are provided to the suspend command when the `--all-global` flag is used. --- lib/vagrant/errors.rb | 4 ++++ plugins/commands/suspend/command.rb | 4 ++++ templates/locales/en.yml | 2 ++ test/unit/plugins/commands/suspend/command_test.rb | 8 ++++++++ 4 files changed, 18 insertions(+) diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index 961d217bd..9b57c466f 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -300,6 +300,10 @@ module Vagrant error_key(:command_deprecated) end + class CommandSuspendAllArgs < VagrantError + error_key(:command_suspend_all_arguments) + end + class CommandUnavailable < VagrantError error_key(:command_unavailable) end diff --git a/plugins/commands/suspend/command.rb b/plugins/commands/suspend/command.rb index 7549e7fd2..519537968 100644 --- a/plugins/commands/suspend/command.rb +++ b/plugins/commands/suspend/command.rb @@ -24,6 +24,10 @@ module VagrantPlugins @logger.debug("'suspend' each target VM...") target = [] if options[:all] + if argv.size > 0 + raise Vagrant::Errors::CommandSuspendAllArgs + end + m = @env.machine_index.each { |m| m } target = m.keys else diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 99ccc67a3..71373d4ac 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -727,6 +727,8 @@ en: command_deprecated: |- The command 'vagrant %{name}' has been deprecated and is no longer functional within Vagrant. + command_suspend_all_arguments: |- + The suspend command with the `--all-global` flag does not take any arguments. command_unavailable: |- The executable '%{file}' Vagrant is trying to run was not found in the PATH variable. This is an error. Please verify diff --git a/test/unit/plugins/commands/suspend/command_test.rb b/test/unit/plugins/commands/suspend/command_test.rb index a6654bef3..3c13c6c5a 100644 --- a/test/unit/plugins/commands/suspend/command_test.rb +++ b/test/unit/plugins/commands/suspend/command_test.rb @@ -99,5 +99,13 @@ describe VagrantPlugins::CommandSuspend::Command do expect(subject.execute).to eq(0) end + + context "with an argument is used" do + let(:argv){ ["machine", "--all-global"] } + + it "errors out" do + expect{subject.execute}.to raise_error(Vagrant::Errors::CommandSuspendAllArgs) + end + end end end