Skip to content

Commit

Permalink
Access table internally
Browse files Browse the repository at this point in the history
  • Loading branch information
dduugg committed Dec 7, 2024
1 parent 607c180 commit 79bf2ae
Showing 1 changed file with 7 additions and 34 deletions.
41 changes: 7 additions & 34 deletions Library/Homebrew/cli/args.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@ def initialize
@options_only = T.let([], T::Array[String])
@flags_only = T.let([], T::Array[String])
@cask_options = T.let(false, T::Boolean)
@table = T.let({
build_bottle?: false,
build_from_source?: false,
force_bottle?: false,
HEAD?: false,
include_test?: false,
}, T::Hash[Symbol, T.untyped])
@table = T.let({}, T::Hash[Symbol, T.untyped])

# Can set these because they will be overwritten by freeze_named_args!
# (whereas other values below will only be overwritten if passed).
Expand All @@ -47,36 +41,15 @@ def freeze_named_args!(named_args, cask_options:, without_api:)
*named_args.freeze,
cask_options:,
flags: flags_only,
force_bottle: force_bottle?,
override_spec: self.HEAD? ? :head : nil,
force_bottle: @table[:force_bottle?] || false,
override_spec: @table[:HEAD?] ? :head : nil,
parent: self,
without_api:,
),
T.nilable(NamedArgs),
)
end

sig { returns(T.nilable(String)) }
def arch = @table[:arch]

sig { returns(T::Boolean) }
def build_bottle? = @table.fetch(:build_bottle?)

sig { returns(T::Boolean) }
def build_from_source? = @table.fetch(:build_from_source?)

sig { returns(T::Boolean) }
def force_bottle? = @table.fetch(:force_bottle?)

sig { returns(T::Boolean) }
def HEAD? = @table.fetch(:HEAD?)

sig { returns(T::Boolean) }
def include_test? = @table.fetch(:include_test?)

sig { returns(T.nilable(String)) }
def os = @table[:os]

sig { params(name: Symbol, value: T.untyped).void }
def set_arg(name, value)
@table[name] = value
Expand Down Expand Up @@ -112,7 +85,7 @@ def no_named? = named.empty?

sig { returns(T::Array[String]) }
def build_from_source_formulae
if build_from_source? || self.HEAD? || build_bottle?
if @table[:build_from_source?] || @table[:HEAD?] || @table[:build_bottle?]
named.to_formulae.map(&:full_name)
else
[]
Expand All @@ -121,7 +94,7 @@ def build_from_source_formulae

sig { returns(T::Array[String]) }
def include_test_formulae
if include_test?
if @table[:include_test?]
named.to_formulae.map(&:full_name)
else
[]
Expand Down Expand Up @@ -155,7 +128,7 @@ def only_formula_or_cask
def os_arch_combinations
skip_invalid_combinations = false

oses = case (os_sym = os&.to_sym)
oses = case (os_sym = @table[:os]&.to_sym)
when nil
[SimulateSystem.current_os]
when :all
Expand All @@ -166,7 +139,7 @@ def os_arch_combinations
[os_sym]
end

arches = case (arch_sym = arch&.to_sym)
arches = case (arch_sym = @table[:arch]&.to_sym)
when nil
[SimulateSystem.current_arch]
when :all
Expand Down

0 comments on commit 79bf2ae

Please sign in to comment.