diff --git a/Library/Homebrew/cli/args.rbi b/Library/Homebrew/cli/args.rbi index a578179d31..bb9d9a9716 100644 --- a/Library/Homebrew/cli/args.rbi +++ b/Library/Homebrew/cli/args.rbi @@ -299,6 +299,9 @@ module Homebrew sig { returns(T::Boolean) } def custom_remote?; end + + sig { returns(T::Boolean) } + def print_path?; end end end end diff --git a/Library/Homebrew/cli/named_args.rb b/Library/Homebrew/cli/named_args.rb index 74df168f2f..9a53f77cb5 100644 --- a/Library/Homebrew/cli/named_args.rb +++ b/Library/Homebrew/cli/named_args.rb @@ -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. diff --git a/Library/Homebrew/dev-cmd/edit.rb b/Library/Homebrew/dev-cmd/edit.rb index 4a50d23926..4c6d1ca34f 100644 --- a/Library/Homebrew/dev-cmd/edit.rb +++ b/Library/Homebrew/dev-cmd/edit.rb @@ -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 diff --git a/Library/Homebrew/dev-cmd/formula.rb b/Library/Homebrew/dev-cmd/formula.rb index a2ba3be2b5..ec5dca7997 100644 --- a/Library/Homebrew/dev-cmd/formula.rb +++ b/Library/Homebrew/dev-cmd/formula.rb @@ -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