Print help message if user provides and ambiguous option

This commit is contained in:
sophia 2020-07-06 10:39:53 -05:00
parent 7df0e62ade
commit 1661d1f1cf
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| }