Merge pull request #11923 from FnControlOption/cli
cli/parser: allow commands that look like options
This commit is contained in:
commit
37739df38a
@ -264,6 +264,7 @@ module Homebrew
|
||||
remaining = []
|
||||
|
||||
argv, non_options = split_non_options(argv)
|
||||
allow_commands = Array(@named_args_type).include?(:command)
|
||||
|
||||
while i < argv.count
|
||||
begin
|
||||
@ -279,7 +280,7 @@ module Homebrew
|
||||
i += 1
|
||||
end
|
||||
rescue OptionParser::InvalidOption
|
||||
if ignore_invalid_options
|
||||
if ignore_invalid_options || (allow_commands && Commands.path(arg))
|
||||
remaining << arg
|
||||
else
|
||||
$stderr.puts generate_help_text
|
||||
|
||||
@ -559,5 +559,19 @@ describe Homebrew::CLI::Parser do
|
||||
Homebrew::CLI::MaxNamedArgumentsError, /This command does not take more than 1 formula or cask argument/
|
||||
)
|
||||
end
|
||||
|
||||
it "accepts commands with :command" do
|
||||
parser = described_class.new do
|
||||
named_args :command
|
||||
end
|
||||
expect { parser.parse(["--prefix", "--version"]) }.not_to raise_error
|
||||
end
|
||||
|
||||
it "doesn't accept invalid options with :command" do
|
||||
parser = described_class.new do
|
||||
named_args :command
|
||||
end
|
||||
expect { parser.parse(["--not-a-command"]) }.to raise_error(OptionParser::InvalidOption, /--not-a-command/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user