Skip to content

Commit

Permalink
Make cli_args idiomatic
Browse files Browse the repository at this point in the history
  • Loading branch information
dduugg committed Dec 7, 2024
1 parent 79bf2ae commit 203bd8a
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions Library/Homebrew/cli/args.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,22 +169,18 @@ def option_to_name(option)

sig { returns(T::Array[String]) }
def cli_args
return @cli_args if @cli_args

@cli_args = []
@processed_options.each do |short, long|
@cli_args ||= @processed_options.map do |short, long|
option = long || short
switch = :"#{option_to_name(option)}?"
flag = option_to_name(option).to_sym
if @table[switch] == true || @table[flag] == true
@cli_args << option
option
elsif @table[flag].instance_of? String
@cli_args << "#{option}=#{@table[flag]}"
"#{option}=#{@table[flag]}"
elsif @table[flag].instance_of? Array
@cli_args << "#{option}=#{@table[flag].join(",")}"
"#{option}=#{@table[flag].join(",")}"
end
end
@cli_args.freeze
end.compact.freeze
end
end
end
Expand Down

0 comments on commit 203bd8a

Please sign in to comment.