Merge pull request #5530 from GauthamGoli/helptext-for-invalid-opt
cli_parser: Output help text on invalid option passed
This commit is contained in:
commit
ab7a3c966f
@ -123,7 +123,12 @@ module Homebrew
|
||||
end
|
||||
|
||||
def parse(cmdline_args = ARGV)
|
||||
remaining_args = @parser.parse(cmdline_args)
|
||||
begin
|
||||
remaining_args = @parser.parse(cmdline_args)
|
||||
rescue OptionParser::InvalidOption => e
|
||||
$stderr.puts generate_help_text
|
||||
raise e
|
||||
end
|
||||
check_constraint_violations
|
||||
Homebrew.args[:remaining] = remaining_args
|
||||
Homebrew.args.freeze
|
||||
|
||||
@ -11,8 +11,8 @@ describe Homebrew::CLI::Parser do
|
||||
}
|
||||
|
||||
before do
|
||||
allow(ENV).to receive(:[])
|
||||
allow(ENV).to receive(:[]).with("HOMEBREW_PRY").and_return("1")
|
||||
allow(ENV).to receive(:[]).with("HOMEBREW_VERBOSE")
|
||||
end
|
||||
|
||||
it "parses short option" do
|
||||
@ -38,8 +38,9 @@ describe Homebrew::CLI::Parser do
|
||||
expect(Homebrew.args.more_verbose?).to be nil
|
||||
end
|
||||
|
||||
it "raises an exception when an invalid option is passed" do
|
||||
it "raises an exception and outputs help text when an invalid option is passed" do
|
||||
expect { parser.parse(["--random"]) }.to raise_error(OptionParser::InvalidOption, /--random/)
|
||||
.and output(/Usage: brew/).to_stderr
|
||||
end
|
||||
|
||||
it "maps environment var to an option" do
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user