Skip to content

Commit 15b81c8

Browse files
committed
Make cli_args idiomatic
1 parent 79bf2ae commit 15b81c8

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

Library/Homebrew/cli/args.rb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,22 +169,18 @@ def option_to_name(option)
169169

170170
sig { returns(T::Array[String]) }
171171
def cli_args
172-
return @cli_args if @cli_args
173-
174-
@cli_args = []
175-
@processed_options.each do |short, long|
172+
@cli_args ||= @processed_options.filter_map do |short, long|
176173
option = long || short
177174
switch = :"#{option_to_name(option)}?"
178175
flag = option_to_name(option).to_sym
179176
if @table[switch] == true || @table[flag] == true
180-
@cli_args << option
177+
option
181178
elsif @table[flag].instance_of? String
182-
@cli_args << "#{option}=#{@table[flag]}"
179+
"#{option}=#{@table[flag]}"
183180
elsif @table[flag].instance_of? Array
184-
@cli_args << "#{option}=#{@table[flag].join(",")}"
181+
"#{option}=#{@table[flag].join(",")}"
185182
end
186-
end
187-
@cli_args.freeze
183+
end.freeze
188184
end
189185
end
190186
end

0 commit comments

Comments
 (0)