cli: fix options handling.
Fix breaking options on taps again (second time in two weeks, sob). To avoid doing this again: also add a test for this case (that I've verified would have caught these cases).
This commit is contained in:
parent
954c833de2
commit
c91f397605
@ -13,6 +13,10 @@ module Homebrew
|
||||
|
||||
@processed_options = []
|
||||
|
||||
# Can set these because they will be overwritten by freeze_named_args!
|
||||
# (whereas other values below will only be overwritten if passed).
|
||||
self[:named_args] = argv.reject { |arg| arg.start_with?("-") }
|
||||
|
||||
# Set values needed before Parser#parse has been run.
|
||||
return unless set_default_args
|
||||
|
||||
@ -22,15 +26,24 @@ module Homebrew
|
||||
self[:HEAD?] = argv.include?("--HEAD")
|
||||
self[:devel?] = argv.include?("--devel")
|
||||
self[:universal?] = argv.include?("--universal")
|
||||
self[:named_args] = argv.reject { |arg| arg.start_with?("-") }
|
||||
end
|
||||
|
||||
def freeze_named_args!(named_args)
|
||||
# Reset cache values reliant on named_args
|
||||
@formulae = nil
|
||||
@resolved_formulae = nil
|
||||
@formulae_paths = nil
|
||||
@casks = nil
|
||||
@kegs = nil
|
||||
|
||||
self[:named_args] = named_args
|
||||
self[:named_args].freeze
|
||||
end
|
||||
|
||||
def freeze_processed_options!(processed_options)
|
||||
# Reset cache values reliant on processed_options
|
||||
@cli_args = nil
|
||||
|
||||
@processed_options += processed_options
|
||||
@processed_options.freeze
|
||||
end
|
||||
|
||||
@ -166,7 +166,6 @@ module Homebrew
|
||||
check_constraint_violations
|
||||
check_named_args(named_args, allow_no_named_args: allow_no_named_args)
|
||||
@args.freeze_named_args!(named_args)
|
||||
parse_formula_options
|
||||
@args.freeze_processed_options!(@processed_options)
|
||||
Homebrew.args = @args
|
||||
|
||||
@ -189,7 +188,21 @@ module Homebrew
|
||||
end
|
||||
|
||||
def formula_options
|
||||
@parse_formula_options = true
|
||||
@args.formulae.each do |f|
|
||||
next if f.options.empty?
|
||||
|
||||
f.options.each do |o|
|
||||
name = o.flag
|
||||
description = "`#{f.name}`: #{o.description}"
|
||||
if name.end_with? "="
|
||||
flag name, description: description
|
||||
else
|
||||
switch name, description: description
|
||||
end
|
||||
end
|
||||
end
|
||||
rescue FormulaUnavailableError
|
||||
[]
|
||||
end
|
||||
|
||||
def max_named(count)
|
||||
@ -228,26 +241,6 @@ module Homebrew
|
||||
|
||||
private
|
||||
|
||||
def parse_formula_options
|
||||
return unless @parse_formula_options
|
||||
|
||||
@args.formulae.each do |f|
|
||||
next if f.options.empty?
|
||||
|
||||
f.options.each do |o|
|
||||
name = o.flag
|
||||
description = "`#{f.name}`: #{o.description}"
|
||||
if name.end_with? "="
|
||||
flag name, description: description
|
||||
else
|
||||
switch name, description: description
|
||||
end
|
||||
end
|
||||
end
|
||||
rescue FormulaUnavailableError
|
||||
[]
|
||||
end
|
||||
|
||||
def enable_switch(*names, from:)
|
||||
names.each do |name|
|
||||
@switch_sources[option_to_name(name)] = from
|
||||
|
||||
@ -14,6 +14,17 @@ describe "brew install", :integration_test do
|
||||
.to output(%r{#{HOMEBREW_CELLAR}/testball1/0\.1}).to_stdout
|
||||
.and not_to_output.to_stderr
|
||||
.and be_a_success
|
||||
expect(HOMEBREW_CELLAR/"testball1/0.1/foo/test").not_to be_a_file
|
||||
end
|
||||
|
||||
it "installs formulae with options" do
|
||||
setup_test_formula "testball1"
|
||||
|
||||
expect { brew "install", "testball1", "--with-foo" }
|
||||
.to output(%r{#{HOMEBREW_CELLAR}/testball1/0\.1}).to_stdout
|
||||
.and not_to_output.to_stderr
|
||||
.and be_a_success
|
||||
expect(HOMEBREW_CELLAR/"testball1/0.1/foo/test").to be_a_file
|
||||
end
|
||||
|
||||
it "can install keg-only Formulae" do
|
||||
@ -27,6 +38,7 @@ describe "brew install", :integration_test do
|
||||
.to output(%r{#{HOMEBREW_CELLAR}/testball1/1\.0}).to_stdout
|
||||
.and not_to_output.to_stderr
|
||||
.and be_a_success
|
||||
expect(HOMEBREW_CELLAR/"testball1/1.0/foo/test").not_to be_a_file
|
||||
end
|
||||
|
||||
it "can install HEAD Formulae" do
|
||||
@ -59,5 +71,6 @@ describe "brew install", :integration_test do
|
||||
.to output(%r{#{HOMEBREW_CELLAR}/testball1/HEAD\-d5eb689}).to_stdout
|
||||
.and output(/Cloning into/).to_stderr
|
||||
.and be_a_success
|
||||
expect(HOMEBREW_CELLAR/"testball1/HEAD-d5eb689/foo/test").not_to be_a_file
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user