Add --print-path flag to brew edit

Add a `--print-path` flag to `brew edit`, in order to print the source `.rb`
file of both casks and formulae. In order to prevent faulty reporting, `brew
formula $SOME_CASK` will now error out if a cask matches, but a formula does
not.
This commit is contained in:
Nathan Woythaler 2021-10-13 10:27:12 -06:00 committed by Mike McQuaid
parent e771571d69
commit 0b8605bcbe
No known key found for this signature in database
GPG Key ID: 3338A31AFDB1D829
4 changed files with 18 additions and 5 deletions

View File

@ -296,6 +296,9 @@ module Homebrew
sig { returns(T::Boolean) }
def custom_remote?; end
sig { returns(T::Boolean) }
def print_path?; end
end
end
end

View File

@ -186,10 +186,6 @@ module Homebrew
to_formulae_to_casks(only: only, method: :resolve)
end
def to_formulae_paths
to_paths(only: :formula)
end
# Keep existing paths and try to convert others to tap, formula or cask paths.
# If a cask and formula with the same name exist, includes both their paths
# unless `only` is specified.

View File

@ -21,6 +21,8 @@ module Homebrew
description: "Treat all named arguments as formulae."
switch "--cask", "--casks",
description: "Treat all named arguments as casks."
switch "--print-path",
description: "Print the file path to be edited, without opening an editor."
conflicts "--formula", "--cask"
@ -59,6 +61,11 @@ module Homebrew
end.presence
end
if args.print_path?
paths.each(&method(:puts))
return
end
exec_editor(*paths)
end
end

View File

@ -23,6 +23,13 @@ module Homebrew
def formula
args = formula_args.parse
args.named.to_formulae_paths.each(&method(:puts))
formula_paths = args.named.to_paths(only: :formula).select(&:exist?)
if formula_paths.blank? && args.named
.to_paths(only: :cask)
.select(&:exist?)
.present?
odie "Found casks but did not find formulae!"
end
formula_paths.each(&method(:puts))
end
end