Merge pull request #11746 from soapy1/ambiguous-option

Print help message if user provides and ambiguous option
This commit is contained in:
Sophia Castellarin 2020-07-06 11:38:28 -05:00 committed by GitHub
commit 9da33520e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -61,7 +61,7 @@ module Vagrant
opts.parse!(argv)
return argv
rescue OptionParser::InvalidOption, OptionParser::MissingArgument
rescue OptionParser::InvalidOption, OptionParser::MissingArgument, OptionParser::AmbiguousOption
raise Errors::CLIInvalidOptions, help: opts.help.chomp
end

View File

@ -46,6 +46,12 @@ describe Vagrant::Plugin::V2::Command do
to raise_error(Vagrant::Errors::CLIInvalidOptions)
end
it "raises an error if ambiguous options are given" do
instance = klass.new(["-provision"], nil)
expect { instance.parse_options(OptionParser.new) }.
to raise_error(Vagrant::Errors::CLIInvalidOptions)
end
it "raises an error if options without a value are given" do
opts = OptionParser.new do |o|
o.on("--provision-with x,y,z", Array, "Example") { |f| }