diff --git a/Library/Homebrew/cli_parser.rb b/Library/Homebrew/cli_parser.rb index 56ca66be31..e487e8580a 100644 --- a/Library/Homebrew/cli_parser.rb +++ b/Library/Homebrew/cli_parser.rb @@ -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 + puts generate_help_text + raise e + end check_constraint_violations Homebrew.args[:remaining] = remaining_args Homebrew.args.freeze diff --git a/Library/Homebrew/test/cli_parser_spec.rb b/Library/Homebrew/test/cli_parser_spec.rb index 891de621eb..b26cf6b444 100644 --- a/Library/Homebrew/test/cli_parser_spec.rb +++ b/Library/Homebrew/test/cli_parser_spec.rb @@ -42,6 +42,10 @@ describe Homebrew::CLI::Parser do expect { parser.parse(["--random"]) }.to raise_error(OptionParser::InvalidOption, /--random/) 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 parser.parse([]) expect(Homebrew.args.pry?).to be true