Nathan Woythaler 0b8605bcbe
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.
2021-10-20 09:04:59 +01:00

36 lines
783 B
Ruby

# typed: true
# frozen_string_literal: true
require "formula"
require "cli/parser"
module Homebrew
extend T::Sig
module_function
sig { returns(CLI::Parser) }
def formula_args
Homebrew::CLI::Parser.new do
description <<~EOS
Display the path where <formula> is located.
EOS
named_args :formula, min: 1
end
end
def formula
args = formula_args.parse
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