dev-cmd/edit: suggest tapping core repositories
This commit is contained in:
parent
799417343a
commit
b3ecd91f97
@ -244,7 +244,7 @@ module Cask
|
|||||||
|
|
||||||
def initialize(token, from_json: nil)
|
def initialize(token, from_json: nil)
|
||||||
@token = token.sub(%r{^homebrew/(?:homebrew-)?cask/}i, "")
|
@token = token.sub(%r{^homebrew/(?:homebrew-)?cask/}i, "")
|
||||||
@path = CaskLoader.default_path(token)
|
@path = CaskLoader.default_path(@token)
|
||||||
@from_json = from_json
|
@from_json = from_json
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -228,8 +228,9 @@ module Homebrew
|
|||||||
def to_paths(only: parent&.only_formula_or_cask, recurse_tap: false)
|
def to_paths(only: parent&.only_formula_or_cask, recurse_tap: false)
|
||||||
@to_paths ||= {}
|
@to_paths ||= {}
|
||||||
@to_paths[only] ||= downcased_unique_named.flat_map do |name|
|
@to_paths[only] ||= downcased_unique_named.flat_map do |name|
|
||||||
|
path = Pathname(name)
|
||||||
if File.exist?(name)
|
if File.exist?(name)
|
||||||
Pathname(name)
|
path
|
||||||
elsif name.count("/") == 1 && !name.start_with?("./", "/")
|
elsif name.count("/") == 1 && !name.start_with?("./", "/")
|
||||||
tap = Tap.fetch(name)
|
tap = Tap.fetch(name)
|
||||||
|
|
||||||
@ -248,10 +249,16 @@ module Homebrew
|
|||||||
|
|
||||||
paths = []
|
paths = []
|
||||||
|
|
||||||
paths << formula_path if formula_path.exist?
|
if formula_path.exist? ||
|
||||||
paths << cask_path if cask_path.exist?
|
(!CoreTap.instance.installed? && Homebrew::API::Formula.all_formulae.key?(path.basename))
|
||||||
|
paths << formula_path
|
||||||
|
end
|
||||||
|
if cask_path.exist? ||
|
||||||
|
(!CoreCaskTap.instance.installed? && Homebrew::API::Cask.all_casks.key?(path.basename))
|
||||||
|
paths << cask_path
|
||||||
|
end
|
||||||
|
|
||||||
paths.empty? ? Pathname(name) : paths
|
paths.empty? ? path : paths
|
||||||
end
|
end
|
||||||
end.uniq.freeze
|
end.uniq.freeze
|
||||||
end
|
end
|
||||||
|
|||||||
@ -11,8 +11,8 @@ module Homebrew
|
|||||||
def edit_args
|
def edit_args
|
||||||
Homebrew::CLI::Parser.new do
|
Homebrew::CLI::Parser.new do
|
||||||
description <<~EOS
|
description <<~EOS
|
||||||
Open a <formula> or <cask> in the editor set by `EDITOR` or `HOMEBREW_EDITOR`,
|
Open a <formula>, <cask> or <tap> in the editor set by `EDITOR` or `HOMEBREW_EDITOR`,
|
||||||
or open the Homebrew repository for editing if no formula is provided.
|
or open the Homebrew repository for editing if no argument is provided.
|
||||||
EOS
|
EOS
|
||||||
|
|
||||||
switch "--formula", "--formulae",
|
switch "--formula", "--formulae",
|
||||||
@ -24,7 +24,7 @@ module Homebrew
|
|||||||
|
|
||||||
conflicts "--formula", "--cask"
|
conflicts "--formula", "--cask"
|
||||||
|
|
||||||
named_args [:formula, :cask], without_api: true
|
named_args [:formula, :cask, :tap], without_api: true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -50,44 +50,58 @@ module Homebrew
|
|||||||
[HOMEBREW_REPOSITORY]
|
[HOMEBREW_REPOSITORY]
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
edit_api_message_displayed = T.let(false, T::Boolean)
|
||||||
args.named.to_paths.select do |path|
|
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?
|
if path.exist?
|
||||||
"#{path.basename(".rb")} doesn't exist on disk."
|
if (core_formula_path || core_cask_path || core_formula_tap || core_cask_tap) &&
|
||||||
else
|
!edit_api_message_displayed &&
|
||||||
"#{path} doesn't exist on disk."
|
!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
|
end
|
||||||
|
|
||||||
message = if args.cask?
|
name = path.basename(".rb").to_s
|
||||||
<<~EOS
|
|
||||||
#{not_exist_message}
|
if (tap_match = Regexp.new(HOMEBREW_TAP_DIR_REGEX.source + /$/.source).match(path.to_s))
|
||||||
Run #{Formatter.identifier("brew create --cask --set-name #{path.basename(".rb")} $URL")} \
|
raise TapUnavailableError, CoreTap.instance.name if core_formula_tap
|
||||||
to create a new cask!
|
raise TapUnavailableError, CoreCaskTap.instance.name if core_cask_tap
|
||||||
EOS
|
|
||||||
|
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
|
else
|
||||||
<<~EOS
|
command = "brew create --set-name #{name} $URL"
|
||||||
#{not_exist_message}
|
action = "create a new formula"
|
||||||
Run #{Formatter.identifier("brew create --set-name #{path.basename} $URL")} \
|
|
||||||
to create a new formula!
|
|
||||||
EOS
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
message = <<~EOS
|
||||||
|
#{name} doesn't exist on disk.
|
||||||
|
Run #{Formatter.identifier(command)} to #{action}!
|
||||||
|
EOS
|
||||||
raise UsageError, message
|
raise UsageError, message
|
||||||
end.presence
|
end.presence
|
||||||
end
|
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.
|
|
||||||
EOS
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if args.print_path?
|
if args.print_path?
|
||||||
paths.each(&method(:puts))
|
paths.each(&method(:puts))
|
||||||
return
|
return
|
||||||
|
|||||||
@ -304,9 +304,19 @@ class TapUnavailableError < RuntimeError
|
|||||||
def initialize(name)
|
def initialize(name)
|
||||||
@name = name
|
@name = name
|
||||||
|
|
||||||
super <<~EOS
|
message = "No available tap #{name}.\n"
|
||||||
No available tap #{name}.
|
if [CoreTap.instance.name, CoreCaskTap.instance.name].include?(name)
|
||||||
EOS
|
command = "brew tap --force #{name}"
|
||||||
|
message += <<~EOS
|
||||||
|
Run #{Formatter.identifier(command)} to tap #{name}!
|
||||||
|
EOS
|
||||||
|
else
|
||||||
|
command = "brew tap-new #{name}"
|
||||||
|
message += <<~EOS
|
||||||
|
Run #{Formatter.identifier(command)} to create a new #{name} tap!
|
||||||
|
EOS
|
||||||
|
end
|
||||||
|
super message.freeze
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -1004,7 +1004,8 @@ module Formulary
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.find_formula_in_tap(name, tap)
|
def self.find_formula_in_tap(name, tap)
|
||||||
filename = "#{name}.rb"
|
filename = name.dup
|
||||||
|
filename << ".rb" unless filename.end_with?(".rb")
|
||||||
|
|
||||||
Tap.formula_files_by_name(tap).fetch(filename, tap.formula_dir/filename)
|
Tap.formula_files_by_name(tap).fetch(filename, tap.formula_dir/filename)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -131,7 +131,7 @@ describe "Exception" do
|
|||||||
describe TapUnavailableError do
|
describe TapUnavailableError do
|
||||||
subject { described_class.new("foo") }
|
subject { described_class.new("foo") }
|
||||||
|
|
||||||
its(:to_s) { is_expected.to eq("No available tap foo.\n") }
|
its(:to_s) { is_expected.to eq("No available tap foo.\nRun brew tap-new foo to create a new foo tap!\n") }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe TapAlreadyTappedError do
|
describe TapAlreadyTappedError do
|
||||||
|
|||||||
@ -927,6 +927,7 @@ _brew_edit() {
|
|||||||
esac
|
esac
|
||||||
__brew_complete_formulae
|
__brew_complete_formulae
|
||||||
__brew_complete_casks
|
__brew_complete_casks
|
||||||
|
__brew_complete_tapped
|
||||||
}
|
}
|
||||||
|
|
||||||
_brew_environment() {
|
_brew_environment() {
|
||||||
|
|||||||
@ -670,7 +670,7 @@ __fish_brew_complete_arg 'dr' -l verbose -d 'Make some output more verbose'
|
|||||||
__fish_brew_complete_arg 'dr' -a '(__fish_brew_suggest_diagnostic_checks)'
|
__fish_brew_complete_arg 'dr' -a '(__fish_brew_suggest_diagnostic_checks)'
|
||||||
|
|
||||||
|
|
||||||
__fish_brew_complete_cmd 'edit' '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'
|
__fish_brew_complete_cmd 'edit' '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'
|
||||||
__fish_brew_complete_arg 'edit' -l cask -d 'Treat all named arguments as casks'
|
__fish_brew_complete_arg 'edit' -l cask -d 'Treat all named arguments as casks'
|
||||||
__fish_brew_complete_arg 'edit' -l debug -d 'Display any debugging information'
|
__fish_brew_complete_arg 'edit' -l debug -d 'Display any debugging information'
|
||||||
__fish_brew_complete_arg 'edit' -l formula -d 'Treat all named arguments as formulae'
|
__fish_brew_complete_arg 'edit' -l formula -d 'Treat all named arguments as formulae'
|
||||||
@ -680,6 +680,7 @@ __fish_brew_complete_arg 'edit' -l quiet -d 'Make some output more quiet'
|
|||||||
__fish_brew_complete_arg 'edit' -l verbose -d 'Make some output more verbose'
|
__fish_brew_complete_arg 'edit' -l verbose -d 'Make some output more verbose'
|
||||||
__fish_brew_complete_arg 'edit; and not __fish_seen_argument -l cask -l casks' -a '(__fish_brew_suggest_formulae_all)'
|
__fish_brew_complete_arg 'edit; and not __fish_seen_argument -l cask -l casks' -a '(__fish_brew_suggest_formulae_all)'
|
||||||
__fish_brew_complete_arg 'edit; and not __fish_seen_argument -l formula -l formulae' -a '(__fish_brew_suggest_casks_all)'
|
__fish_brew_complete_arg 'edit; and not __fish_seen_argument -l formula -l formulae' -a '(__fish_brew_suggest_casks_all)'
|
||||||
|
__fish_brew_complete_arg 'edit' -a '(__fish_brew_suggest_taps_installed)'
|
||||||
|
|
||||||
|
|
||||||
__fish_brew_complete_cmd 'environment' 'Summarise Homebrew\'s build environment as a plain list'
|
__fish_brew_complete_cmd 'environment' 'Summarise Homebrew\'s build environment as a plain list'
|
||||||
|
|||||||
@ -164,7 +164,7 @@ __brew_internal_commands() {
|
|||||||
'dispatch-build-bottle:Build bottles for these formulae with GitHub Actions'
|
'dispatch-build-bottle:Build bottles for these formulae with GitHub Actions'
|
||||||
'docs:Open Homebrew'\''s online documentation (https://docs.brew.sh) in a browser'
|
'docs:Open Homebrew'\''s online documentation (https://docs.brew.sh) in a browser'
|
||||||
'doctor:Check your system for potential problems'
|
'doctor:Check your system for potential problems'
|
||||||
'edit: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'
|
'edit: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'
|
||||||
'extract:Look through repository history to find the most recent version of formula and create a copy in tap'
|
'extract:Look through repository history to find the most recent version of formula and create a copy in tap'
|
||||||
'fetch:Download a bottle (if available) or source packages for formulae and binaries for casks'
|
'fetch:Download a bottle (if available) or source packages for formulae and binaries for casks'
|
||||||
'formula:Display the path where formula is located'
|
'formula:Display the path where formula is located'
|
||||||
@ -853,7 +853,9 @@ _brew_edit() {
|
|||||||
'*::formula:__brew_formulae' \
|
'*::formula:__brew_formulae' \
|
||||||
- cask \
|
- cask \
|
||||||
'(--formula)--cask[Treat all named arguments as casks]' \
|
'(--formula)--cask[Treat all named arguments as casks]' \
|
||||||
'*::cask:__brew_casks'
|
'*::cask:__brew_casks' \
|
||||||
|
- tap \
|
||||||
|
'*::tap:__brew_any_tap'
|
||||||
}
|
}
|
||||||
|
|
||||||
# brew environment
|
# brew environment
|
||||||
|
|||||||
@ -1240,10 +1240,10 @@ Build bottles for these formulae with GitHub Actions.
|
|||||||
* `--linux-wheezy`:
|
* `--linux-wheezy`:
|
||||||
Use Debian Wheezy container for building the bottle on Linux.
|
Use Debian Wheezy container for building the bottle on Linux.
|
||||||
|
|
||||||
### `edit` [*`options`*] [*`formula`*|*`cask`* ...]
|
### `edit` [*`options`*] [*`formula`*|*`cask`*|*`tap`* ...]
|
||||||
|
|
||||||
Open a *`formula`* or *`cask`* in the editor set by `EDITOR` or `HOMEBREW_EDITOR`,
|
Open a *`formula`*, *`cask`* or *`tap`* in the editor set by `EDITOR` or `HOMEBREW_EDITOR`,
|
||||||
or open the Homebrew repository for editing if no formula is provided.
|
or open the Homebrew repository for editing if no argument is provided.
|
||||||
|
|
||||||
* `--formula`:
|
* `--formula`:
|
||||||
Treat all named arguments as formulae.
|
Treat all named arguments as formulae.
|
||||||
|
|||||||
@ -1804,8 +1804,8 @@ Dispatch bottle for Linux (using self\-hosted runner)\.
|
|||||||
\fB\-\-linux\-wheezy\fR
|
\fB\-\-linux\-wheezy\fR
|
||||||
Use Debian Wheezy container for building the bottle on Linux\.
|
Use Debian Wheezy container for building the bottle on Linux\.
|
||||||
.
|
.
|
||||||
.SS "\fBedit\fR [\fIoptions\fR] [\fIformula\fR|\fIcask\fR \.\.\.]"
|
.SS "\fBedit\fR [\fIoptions\fR] [\fIformula\fR|\fIcask\fR|\fItap\fR \.\.\.]"
|
||||||
Open a \fIformula\fR or \fIcask\fR in the editor set by \fBEDITOR\fR or \fBHOMEBREW_EDITOR\fR, or open the Homebrew repository for editing if no formula is provided\.
|
Open a \fIformula\fR, \fIcask\fR or \fItap\fR in the editor set by \fBEDITOR\fR or \fBHOMEBREW_EDITOR\fR, or open the Homebrew repository for editing if no argument is provided\.
|
||||||
.
|
.
|
||||||
.TP
|
.TP
|
||||||
\fB\-\-formula\fR
|
\fB\-\-formula\fR
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user