From 0b8605bcbe03256274b1ec62a2ff458b40448e1d Mon Sep 17 00:00:00 2001 From: Nathan Woythaler Date: Wed, 13 Oct 2021 10:27:12 -0600 Subject: [PATCH] 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. --- Library/Homebrew/cli/args.rbi | 3 +++ Library/Homebrew/cli/named_args.rb | 4 ---- Library/Homebrew/dev-cmd/edit.rb | 7 +++++++ Library/Homebrew/dev-cmd/formula.rb | 9 ++++++++- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/cli/args.rbi b/Library/Homebrew/cli/args.rbi index a40455d226..efd36eda0a 100644 --- a/Library/Homebrew/cli/args.rbi +++ b/Library/Homebrew/cli/args.rbi @@ -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 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