-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dev-cmd/edit: suggest tapping core repositories if untapped #15740
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,8 @@ module Homebrew | |
def edit_args | ||
Homebrew::CLI::Parser.new do | ||
description <<~EOS | ||
Open a <formula> or <cask> in the editor set by `EDITOR` or `HOMEBREW_EDITOR`, | ||
or open the Homebrew repository for editing if no formula is provided. | ||
Open a <formula>, <cask> or <tap> in the editor set by `EDITOR` or `HOMEBREW_EDITOR`, | ||
or open the Homebrew repository for editing if no argument is provided. | ||
EOS | ||
|
||
switch "--formula", "--formulae", | ||
|
@@ -24,7 +24,7 @@ def edit_args | |
|
||
conflicts "--formula", "--cask" | ||
|
||
named_args [:formula, :cask], without_api: true | ||
named_args [:formula, :cask, :tap], without_api: true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This command hasn't advertised that it handles tap arguments too, until now. |
||
end | ||
end | ||
|
||
|
@@ -50,42 +50,56 @@ def edit | |
[HOMEBREW_REPOSITORY] | ||
end | ||
else | ||
edit_api_message_displayed = T.let(false, T::Boolean) | ||
args.named.to_paths.select do |path| | ||
next path if path.exist? | ||
core_formula_path = path.fnmatch?("**/homebrew-core/Formula/**.rb", File::FNM_DOTMATCH) | ||
core_cask_path = path.fnmatch?("**/homebrew-cask/Casks/**.rb", File::FNM_DOTMATCH) | ||
core_formula_tap = path == CoreTap.instance.path | ||
core_cask_tap = path == CoreCaskTap.instance.path | ||
|
||
not_exist_message = if args.cask? | ||
"#{path.basename(".rb")} doesn't exist on disk." | ||
else | ||
"#{path} doesn't exist on disk." | ||
if path.exist? | ||
if (core_formula_path || core_cask_path || core_formula_tap || core_cask_tap) && | ||
!edit_api_message_displayed && | ||
!Homebrew::EnvConfig.no_install_from_api? && | ||
!Homebrew::EnvConfig.no_env_hints? | ||
opoo <<~EOS | ||
Unless `HOMEBREW_NO_INSTALL_FROM_API` is set when running `brew install`, | ||
it will ignore any locally edited #{(core_cask_path || core_cask_tap) ? "casks" : "formulae"}. | ||
EOS | ||
edit_api_message_displayed = true | ||
end | ||
next path | ||
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 | ||
name = path.basename(".rb").to_s | ||
|
||
if (tap_match = Regexp.new(HOMEBREW_TAP_DIR_REGEX.source + /$/.source).match(path.to_s)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Identifying the tap from a path seems like something we can extract to a method somewhere. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any location in particular? |
||
raise TapUnavailableError, CoreTap.instance.name if core_formula_tap | ||
raise TapUnavailableError, CoreCaskTap.instance.name if core_cask_tap | ||
|
||
raise TapUnavailableError, "#{tap_match[:user]}/#{tap_match[:repo]}" | ||
elsif args.cask? || core_cask_path | ||
if !CoreCaskTap.instance.installed? && Homebrew::API::Cask.all_casks.key?(name) | ||
command = "brew tap --force #{CoreCaskTap.instance.name}" | ||
action = "tap #{CoreCaskTap.instance.name}" | ||
else | ||
command = "brew create --cask --set-name #{name} $URL" | ||
action = "create a new cask" | ||
end | ||
elsif core_formula_path && !CoreTap.instance.installed? && Homebrew::API::Formula.all_formulae.key?(name) | ||
command = "brew tap --force #{CoreTap.instance.name}" | ||
action = "tap #{CoreTap.instance.name}" | ||
else | ||
<<~EOS | ||
#{not_exist_message} | ||
Run #{Formatter.identifier("brew create --set-name #{path.basename} $URL")} \ | ||
to create a new formula! | ||
EOS | ||
command = "brew create --set-name #{name} $URL" | ||
action = "create a new formula" | ||
end | ||
raise UsageError, message | ||
end.presence | ||
end | ||
|
||
if !Homebrew::EnvConfig.no_install_from_api? && !Homebrew::EnvConfig.no_env_hints? | ||
paths.each do |path| | ||
next if !path.fnmatch?("**/homebrew-core/Formula/*.rb") && !path.fnmatch?("**/homebrew-cask/Casks/*.rb") | ||
|
||
opoo <<~EOS | ||
Unless `HOMEBREW_NO_INSTALL_FROM_API` is set when running | ||
`brew install`, it will ignore your locally edited formula. | ||
message = <<~EOS | ||
#{name} doesn't exist on disk. | ||
Run #{Formatter.identifier(command)} to #{action}! | ||
EOS | ||
break | ||
end | ||
raise UsageError, message | ||
end.presence | ||
end | ||
|
||
if args.print_path? | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes an issue where args in the form "user/repo/name" wouldn't be handled properly.