From f18cbd2066d114ad3dec053c2df4845f4621dc6a Mon Sep 17 00:00:00 2001 From: Phoenix Eliot Date: Tue, 11 Jan 2022 14:16:35 -0500 Subject: [PATCH 1/4] Add helpful error message when attempting to run `brew cask` --- Library/Homebrew/brew.rb | 4 ++++ Library/Homebrew/commands.rb | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index 945c14dea1..865fefda9f 100644 --- a/Library/Homebrew/brew.rb +++ b/Library/Homebrew/brew.rb @@ -86,6 +86,10 @@ begin require "commands" require "settings" + # Print an error message and exit if the command is no longer supported + unsupported_cmd_message = Commands.unsupported_cmd?(cmd) + odie unsupported_cmd_message if unsupported_cmd_message + internal_cmd = Commands.valid_internal_cmd?(cmd) || Commands.valid_internal_dev_cmd?(cmd) if cmd unless internal_cmd diff --git a/Library/Homebrew/commands.rb b/Library/Homebrew/commands.rb index e9450b3fed..c67e5dbeff 100644 --- a/Library/Homebrew/commands.rb +++ b/Library/Homebrew/commands.rb @@ -30,6 +30,13 @@ module Commands "lc" => "livecheck", "tc" => "typecheck", }.freeze + HOMEBREW_UNSUPPORTED_COMMAND_MESSAGES = { + "cask" => "`brew cask ` is no longer supported. Use `brew --cask` instead.", + }.freeze + + def unsupported_cmd?(cmd) + HOMEBREW_UNSUPPORTED_COMMAND_MESSAGES.fetch(cmd, nil) + end def valid_internal_cmd?(cmd) require?(HOMEBREW_CMD_PATH/cmd) From 9e2c5910c5d9dda0ed200d947af7bbb69c6386e1 Mon Sep 17 00:00:00 2001 From: Phoenix Eliot Date: Tue, 8 Feb 2022 12:08:32 -0500 Subject: [PATCH 2/4] Simplify 'brew cask' check --- Library/Homebrew/brew.rb | 7 +++---- Library/Homebrew/commands.rb | 7 ------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index 865fefda9f..d1d342cfcd 100644 --- a/Library/Homebrew/brew.rb +++ b/Library/Homebrew/brew.rb @@ -86,10 +86,6 @@ begin require "commands" require "settings" - # Print an error message and exit if the command is no longer supported - unsupported_cmd_message = Commands.unsupported_cmd?(cmd) - odie unsupported_cmd_message if unsupported_cmd_message - internal_cmd = Commands.valid_internal_cmd?(cmd) || Commands.valid_internal_dev_cmd?(cmd) if cmd unless internal_cmd @@ -125,6 +121,9 @@ begin possible_tap = Tap.fetch(possible_tap.first) if possible_tap if !possible_tap || possible_tap.installed? || Tap.untapped_official_taps.include?(possible_tap.name) + if cmd == 'cask' # Check for cask explicitly because it's very common in old guides + odie "`brew cask ` is no longer supported. Use `brew --cask` instead." + end odie "Unknown command: #{cmd}" end diff --git a/Library/Homebrew/commands.rb b/Library/Homebrew/commands.rb index c67e5dbeff..e9450b3fed 100644 --- a/Library/Homebrew/commands.rb +++ b/Library/Homebrew/commands.rb @@ -30,13 +30,6 @@ module Commands "lc" => "livecheck", "tc" => "typecheck", }.freeze - HOMEBREW_UNSUPPORTED_COMMAND_MESSAGES = { - "cask" => "`brew cask ` is no longer supported. Use `brew --cask` instead.", - }.freeze - - def unsupported_cmd?(cmd) - HOMEBREW_UNSUPPORTED_COMMAND_MESSAGES.fetch(cmd, nil) - end def valid_internal_cmd?(cmd) require?(HOMEBREW_CMD_PATH/cmd) From 7a5eb3dbdb943b6dfcc617ee98a883ae36e02001 Mon Sep 17 00:00:00 2001 From: Phoenix Eliot Date: Tue, 8 Feb 2022 12:14:00 -0500 Subject: [PATCH 3/4] Fix rubocop warning --- Library/Homebrew/brew.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index d1d342cfcd..1423097280 100644 --- a/Library/Homebrew/brew.rb +++ b/Library/Homebrew/brew.rb @@ -121,7 +121,7 @@ begin possible_tap = Tap.fetch(possible_tap.first) if possible_tap if !possible_tap || possible_tap.installed? || Tap.untapped_official_taps.include?(possible_tap.name) - if cmd == 'cask' # Check for cask explicitly because it's very common in old guides + if cmd == "cask" # Check for cask explicitly because it's very common in old guides odie "`brew cask ` is no longer supported. Use `brew --cask` instead." end odie "Unknown command: #{cmd}" From 0c520844b4df47d21e63142fbf931237931f3009 Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Fri, 11 Feb 2022 10:49:21 -0500 Subject: [PATCH 4/4] Improve message --- Library/Homebrew/brew.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index 1423097280..4e26545326 100644 --- a/Library/Homebrew/brew.rb +++ b/Library/Homebrew/brew.rb @@ -121,9 +121,8 @@ begin possible_tap = Tap.fetch(possible_tap.first) if possible_tap if !possible_tap || possible_tap.installed? || Tap.untapped_official_taps.include?(possible_tap.name) - if cmd == "cask" # Check for cask explicitly because it's very common in old guides - odie "`brew cask ` is no longer supported. Use `brew --cask` instead." - end + # Check for cask explicitly because it's very common in old guides + odie "`brew cask` is no longer a `brew` command. Use `brew --cask` instead." if cmd == "cask" odie "Unknown command: #{cmd}" end