Skip to content

Commit

Permalink
dev-cmd/edit: suggest tapping core repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
EricFromCanada committed Jul 25, 2023
1 parent 11b17f8 commit 56a6562
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
31 changes: 20 additions & 11 deletions Library/Homebrew/dev-cmd/edit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions Library/Homebrew/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 56a6562

Please sign in to comment.