diff --git a/Library/Homebrew/cli/args.rb b/Library/Homebrew/cli/args.rb index a85d1e5a07..cc2f277e02 100644 --- a/Library/Homebrew/cli/args.rb +++ b/Library/Homebrew/cli/args.rb @@ -21,16 +21,14 @@ module Homebrew end def cli_args - return @cli_args unless @cli_args.nil? + return @cli_args if @cli_args @cli_args = [] processed_options.each do |short, long| option = long || short switch = "#{option_to_name(option)}?".to_sym flag = option_to_name(option).to_sym - if @table[switch].instance_of? TrueClass - @cli_args << option - elsif @table[flag].instance_of? TrueClass + if @table[switch] == true || @table[flag] == true @cli_args << option elsif @table[flag].instance_of? String @cli_args << option + "=" + @table[flag] @@ -48,6 +46,10 @@ module Homebrew def flags_only @flags_only ||= cli_args.select { |arg| arg.start_with?("--") } end + + def passthrough + options_only - CLI::Parser.global_options.values.map(&:first).flatten + end end end end diff --git a/Library/Homebrew/cmd/cat.rb b/Library/Homebrew/cmd/cat.rb index 8c949033a3..8075034046 100644 --- a/Library/Homebrew/cmd/cat.rb +++ b/Library/Homebrew/cmd/cat.rb @@ -25,7 +25,6 @@ module Homebrew raise "`brew cat` doesn't support multiple arguments" if args.remaining.size > 1 cd HOMEBREW_REPOSITORY - cat_args = Homebrew.args.options_only - CLI::Parser.global_options.values.map(&:first).flatten - safe_system "cat", formulae.first.path, *cat_args + safe_system "cat", formulae.first.path, *Homebrew.args.passthrough end end diff --git a/Library/Homebrew/cmd/list.rb b/Library/Homebrew/cmd/list.rb index d02b47a893..a6cd43d331 100644 --- a/Library/Homebrew/cmd/list.rb +++ b/Library/Homebrew/cmd/list.rb @@ -70,8 +70,7 @@ module Homebrew puts Formatter.columns(full_names) else ENV["CLICOLOR"] = nil - ls_args = Homebrew.args.options_only - CLI::Parser.global_options.values.map(&:first).flatten - safe_system "ls", *ls_args << HOMEBREW_CELLAR + safe_system "ls", *Homebrew.args.passthrough << HOMEBREW_CELLAR end elsif args.verbose? || !$stdout.tty? system_command! "find", args: ARGV.kegs.map(&:to_s) + %w[-not -type d -print], print_stdout: true diff --git a/Library/Homebrew/test/cli/parser_spec.rb b/Library/Homebrew/test/cli/parser_spec.rb index d0ef7ad2fc..5d5171f57b 100644 --- a/Library/Homebrew/test/cli/parser_spec.rb +++ b/Library/Homebrew/test/cli/parser_spec.rb @@ -230,5 +230,10 @@ describe Homebrew::CLI::Parser do parser.parse(["--foo", "--bar=value", "-v", "-s", "a", "b", "cdefg"]) expect(Homebrew.args.flags_only).to eq %w[--foo --bar=value --verbose] end + + it "#passthrough" do + parser.parse(["--foo", "--bar=value", "-v", "-s", "a", "b", "cdefg"]) + expect(Homebrew.args.passthrough).to eq %w[--foo --bar=value -s] + end end end