From 56a6562ba3c69a0487bdde3e32c86d27e6a92bfd Mon Sep 17 00:00:00 2001 From: Eric Knibbe Date: Sun, 23 Jul 2023 14:54:25 -0400 Subject: [PATCH] dev-cmd/edit: suggest tapping core repositories --- Library/Homebrew/dev-cmd/edit.rb | 31 ++++++++++++++++++++----------- Library/Homebrew/exceptions.rb | 12 +++++++++--- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/Library/Homebrew/dev-cmd/edit.rb b/Library/Homebrew/dev-cmd/edit.rb index 30be090fece6d6..1f5107284bc170 100644 --- a/Library/Homebrew/dev-cmd/edit.rb +++ b/Library/Homebrew/dev-cmd/edit.rb @@ -59,19 +59,28 @@ def edit "#{path} doesn't exist on disk." end - message = if args.cask? - <<~EOS - #{not_exist_message} - Run #{Formatter.identifier("brew create --cask --set-name #{path.basename(".rb")} $URL")} \ - to create a new cask! - EOS + suggestion_message = if args.cask? + if !CoreCaskTap.instance.installed? && Homebrew::API::Cask.all_casks.key?(path.basename(".rb").to_s) + command = "brew tap --force #{CoreCaskTap.instance.name}" + "Run #{Formatter.identifier(command)} to tap #{CoreCaskTap.instance.name}!" + else + "Run #{Formatter.identifier("brew create --cask --set-name #{path.basename(".rb")} $URL")} " \ + "to create a new cask!" + end else - <<~EOS - #{not_exist_message} - Run #{Formatter.identifier("brew create --set-name #{path.basename} $URL")} \ - to create a new formula! - EOS + if !CoreTap.instance.installed? && Homebrew::API::Formula.all_formulae.key?(path.basename.to_s) + command = "brew tap --force #{CoreTap.instance.name}" + "Run #{Formatter.identifier(command)} to tap #{CoreTap.instance.name}!" + else + "Run #{Formatter.identifier("brew create --set-name #{path.basename} $URL")} " \ + "to create a new formula!" + end end + + message = <<~EOS + #{not_exist_message} + #{suggestion_message} + EOS raise UsageError, message end.presence end diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb index 18bdd2d34112cb..d9bb05cd6b51bf 100644 --- a/Library/Homebrew/exceptions.rb +++ b/Library/Homebrew/exceptions.rb @@ -304,9 +304,15 @@ class TapUnavailableError < RuntimeError def initialize(name) @name = name - super <<~EOS - No available tap #{name}. - EOS + message = "No available tap #{name}." + if [CoreTap.instance.name, CoreCaskTap.instance.name].include?(name) + command = "brew tap --force #{name}" + message += <<~EOS + + Run #{Formatter.identifier(command)} to tap #{name}! + EOS + end + super message.freeze end end