Skip to content
This repository was archived by the owner on Apr 22, 2025. It is now read-only.

Commit b7b83c7

Browse files
committed
cmd/bundle: deduplicate add and remove handling
1 parent 621c2a2 commit b7b83c7

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

cmd/bundle.rb

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -239,36 +239,32 @@ def run
239239
whalebrew: args.whalebrew? || args.all?,
240240
vscode: args.vscode? || args.all?,
241241
)
242-
when "add"
243-
raise UsageError, "`add` does not support `--mas`." if args.mas?
244-
245-
# We intentionally omit the `s` from `brews` and `casks` for ease of handling later.
246-
type_hash = {
247-
brew: args.brews? || no_type_args,
248-
cask: args.casks?,
249-
whalebrew: args.whalebrew?,
250-
vscode: args.vscode?,
251-
}
252-
selected_types = type_hash.select { |_, v| v }.keys
253-
raise UsageError, "`add` supports only one type of entry at a time." if selected_types.count > 1
254-
255-
_subcommand, *named_args = args.named
256-
Bundle::Commands::Add.run(*named_args, type: selected_types.first, global:, file:)
257-
when "remove"
258-
# We intentionally omit the `s` from `brews` and `casks` for ease of handling later.
242+
when "add", "remove"
243+
# We intentionally omit the `s` from `brews`, `casks`, and `taps` for ease of handling later.
259244
type_hash = {
260245
brew: args.brews?,
261246
cask: args.casks?,
247+
tap: args.taps?,
262248
mas: args.mas?,
263249
whalebrew: args.whalebrew?,
264250
vscode: args.vscode?,
265251
none: no_type_args,
266252
}
267253
selected_types = type_hash.select { |_, v| v }.keys
268-
raise UsageError, "`remove` requires exactly one type of entry." if selected_types.count != 1
254+
raise UsageError, "`#{subcommand}` supports only one type of entry at a time." if selected_types.count != 1
269255

270256
_, *named_args = args.named
271-
Bundle::Commands::Remove.run(*named_args, type: selected_types.first, global:, file:)
257+
if subcommand == "add"
258+
type = case (t = selected_types.first)
259+
when :none then :brew
260+
when :mas then raise UsageError, "`add` does not support `--mas`."
261+
else t
262+
end
263+
264+
Bundle::Commands::Add.run(*named_args, type:, global:, file:)
265+
else
266+
Bundle::Commands::Remove.run(*named_args, type: selected_types.first, global:, file:)
267+
end
272268
else
273269
raise UsageError, "unknown subcommand: #{subcommand}"
274270
end

0 commit comments

Comments
 (0)