diff --git a/Library/Homebrew/cli/args.rb b/Library/Homebrew/cli/args.rb index 2a7b81517e7bc..522b2e550cf9b 100644 --- a/Library/Homebrew/cli/args.rb +++ b/Library/Homebrew/cli/args.rb @@ -28,6 +28,14 @@ def options_only .map(&method(:to_cli_option)) .select { |arg| arg.start_with?("-") } end + + def flags_only + to_h.keys + .map(&:to_s) + .reject { |name| %w[argv remaining].include?(name) } + .map(&method(:to_cli_option)) + .select { |arg| arg.start_with?("--") } + end end end end diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index 7ebd0b477ede9..3a3e78e3c429d 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -162,7 +162,7 @@ def upgrade_formula(f) tab = Tab.for_keg(keg) end - build_options = BuildOptions.new(Options.create(ARGV.flags_only), f.options) + build_options = BuildOptions.new(Options.create(Homebrew.args.flags_only), f.options) options = build_options.used_options options |= f.build.used_options options &= f.options diff --git a/Library/Homebrew/reinstall.rb b/Library/Homebrew/reinstall.rb index 51862302a131e..067d8b38e87ee 100644 --- a/Library/Homebrew/reinstall.rb +++ b/Library/Homebrew/reinstall.rb @@ -16,7 +16,7 @@ def reinstall_formula(f, build_from_source: false) backup keg end - build_options = BuildOptions.new(Options.create(ARGV.flags_only), f.options) + build_options = BuildOptions.new(Options.create(Homebrew.args.flags_only), f.options) options = build_options.used_options options |= f.build.used_options options &= f.options diff --git a/Library/Homebrew/test/cli/parser_spec.rb b/Library/Homebrew/test/cli/parser_spec.rb index 4fd34553bb3ad..9e27eca43e3fc 100644 --- a/Library/Homebrew/test/cli/parser_spec.rb +++ b/Library/Homebrew/test/cli/parser_spec.rb @@ -225,5 +225,10 @@ parser.parse(["--foo", "-vds", "a", "b", "cdefg"]) expect(Homebrew.args.options_only).to eq %w[--foo -v -d -s] end + + it "#flags_only" do + parser.parse(["--foo", "-vds", "a", "b", "cdefg"]) + expect(Homebrew.args.flags_only).to eq %w[--foo] + end end end