cli_parser: Output help text on invalid option passed
This commit is contained in:
parent
4f17e2384a
commit
9c7fe3dcb9
@ -123,7 +123,12 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
def parse(cmdline_args = ARGV)
|
def parse(cmdline_args = ARGV)
|
||||||
remaining_args = @parser.parse(cmdline_args)
|
begin
|
||||||
|
remaining_args = @parser.parse(cmdline_args)
|
||||||
|
rescue OptionParser::InvalidOption => e
|
||||||
|
puts generate_help_text
|
||||||
|
raise e
|
||||||
|
end
|
||||||
check_constraint_violations
|
check_constraint_violations
|
||||||
Homebrew.args[:remaining] = remaining_args
|
Homebrew.args[:remaining] = remaining_args
|
||||||
Homebrew.args.freeze
|
Homebrew.args.freeze
|
||||||
|
|||||||
@ -42,6 +42,10 @@ describe Homebrew::CLI::Parser do
|
|||||||
expect { parser.parse(["--random"]) }.to raise_error(OptionParser::InvalidOption, /--random/)
|
expect { parser.parse(["--random"]) }.to raise_error(OptionParser::InvalidOption, /--random/)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "outputs help text on failure" do
|
||||||
|
expect { parser.parse(["--random"]) }.to raise_error(OptionParser::InvalidOption, /Usage: brew/)
|
||||||
|
end
|
||||||
|
|
||||||
it "maps environment var to an option" do
|
it "maps environment var to an option" do
|
||||||
parser.parse([])
|
parser.parse([])
|
||||||
expect(Homebrew.args.pry?).to be true
|
expect(Homebrew.args.pry?).to be true
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user