From ee1da7ec98f08622d925302b2037a690a8935a80 Mon Sep 17 00:00:00 2001 From: Ruoyu Zhong Date: Sat, 7 Dec 2024 10:00:53 +0800 Subject: [PATCH] cmd/alias: refactor This fixes the typecheck issues due to Homebrew/brew#18867. The logic is also refactored to make it hopefully easier to understand than before. This also fixes the issue where the plain `brew alias` command would not print anything due to incorrect usage of `Aliases.show`. --- cmd/alias.rb | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/cmd/alias.rb b/cmd/alias.rb index 55e6cea..36c00e9 100755 --- a/cmd/alias.rb +++ b/cmd/alias.rb @@ -20,26 +20,26 @@ class Alias < AbstractCommand sig { override.void } def run - arg = args.named.first - split_arg = arg.split("=", 2) if arg.present? + name = args.named.first + name, command = name.split("=", 2) if name.present? Aliases.init - if args.edit? - if arg.blank? + if name.nil? + if args.edit? Aliases.edit_all - elsif /.=./.match?(arg) - Aliases.add(*split_arg) - Aliases.edit(split_arg.first) else - Aliases.edit arg + Aliases.each([]) { |name| Aliases::show name } + end + elsif command.nil? + if args.edit? + Aliases.edit name + else + Aliases.show name end - elsif /.=./.match?(arg) - Aliases.add(*split_arg) - elsif arg.present? - Aliases.show arg else - Aliases.show + Aliases.add name, command + Aliases.edit name if args.edit? end end end