diff --git a/Library/Homebrew/cli/named_args.rb b/Library/Homebrew/cli/named_args.rb index a7423991d5..f827bc070f 100644 --- a/Library/Homebrew/cli/named_args.rb +++ b/Library/Homebrew/cli/named_args.rb @@ -117,7 +117,7 @@ module Homebrew private :to_objects def to_formulae_paths - to_paths(only: :formulae) + to_paths(only: :formula) end # Keep existing paths and try to convert others to tap, formula or cask paths. @@ -128,11 +128,11 @@ module Homebrew @to_paths[only] ||= downcased_unique_named.flat_map do |name| if File.exist?(name) Pathname(name) - elsif name.count("/") == 1 + elsif name.count("/") == 1 && !name.start_with?("./", "/") Tap.fetch(name).path else - next Formulary.path(name) if only == :formulae - next Cask::CaskLoader.path(name) if only == :casks + next Formulary.path(name) if only == :formula + next Cask::CaskLoader.path(name) if only == :cask formula_path = Formulary.path(name) cask_path = Cask::CaskLoader.path(name) diff --git a/Library/Homebrew/dev-cmd/cat.rb b/Library/Homebrew/dev-cmd/cat.rb index 625ee66779..3554694d60 100644 --- a/Library/Homebrew/dev-cmd/cat.rb +++ b/Library/Homebrew/dev-cmd/cat.rb @@ -12,18 +12,27 @@ module Homebrew def cat_args Homebrew::CLI::Parser.new do usage_banner <<~EOS - `cat` + `cat` | - Display the source of . + Display the source of a or . EOS - named :formula + switch "--formula", "--formulae", + description: "Treat all named arguments as formulae." + switch "--cask", "--casks", + description: "Treat all named arguments as casks." + conflicts "--formula", "--cask" + + named :formula_or_cask end end def cat args = cat_args.parse + only = :formula if args.formula? && !args.cask? + only = :cask if args.cask? && !args.formula? + cd HOMEBREW_REPOSITORY pager = if Homebrew::EnvConfig.bat? ENV["BAT_CONFIG_PATH"] = Homebrew::EnvConfig.bat_config_path @@ -31,6 +40,7 @@ module Homebrew else "cat" end - safe_system pager, args.named.to_formulae_paths.first + + safe_system pager, args.named.to_paths(only: only).first end end diff --git a/Library/Homebrew/test/cli/named_args_spec.rb b/Library/Homebrew/test/cli/named_args_spec.rb index 29af7187e1..b8efc96cde 100644 --- a/Library/Homebrew/test/cli/named_args_spec.rb +++ b/Library/Homebrew/test/cli/named_args_spec.rb @@ -150,16 +150,16 @@ describe Homebrew::CLI::NamedArgs do expect(described_class.new("foo", "baz").to_paths).to eq [formula_path, cask_path] end - it "returns only formulae when `only: :formulae` is specified" do + it "returns only formulae when `only: :formula` is specified" do expect(Formulary).to receive(:path).with("foo").and_return(formula_path) - expect(described_class.new("foo", "baz").to_paths(only: :formulae)).to eq [formula_path, Formulary.path("baz")] + expect(described_class.new("foo", "baz").to_paths(only: :formula)).to eq [formula_path, Formulary.path("baz")] end - it "returns only casks when `only: :casks` is specified" do + it "returns only casks when `only: :cask` is specified" do expect(Cask::CaskLoader).to receive(:path).with("foo").and_return(cask_path) - expect(described_class.new("foo", "baz").to_paths(only: :casks)).to eq [cask_path, Cask::CaskLoader.path("baz")] + expect(described_class.new("foo", "baz").to_paths(only: :cask)).to eq [cask_path, Cask::CaskLoader.path("baz")] end end end diff --git a/docs/Manpage.md b/docs/Manpage.md index 8bc56518e8..9f5b14a52a 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -915,9 +915,14 @@ present, "revision 1" will be added. * `--message`: Append *`message`* to the default commit message. -### `cat` *`formula`* +### `cat` *`formula`*|*`cask`* -Display the source of *`formula`*. +Display the source of a *`formula`* or *`cask`*. + +* `--formula`: + Treat all named arguments as formulae. +* `--cask`: + Treat all named arguments as casks. ### `command` *`cmd`* diff --git a/manpages/brew.1 b/manpages/brew.1 index ec68ae005e..d0902e08cb 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -1274,8 +1274,16 @@ Print what would be done rather than doing it\. \fB\-\-message\fR Append \fImessage\fR to the default commit message\. . -.SS "\fBcat\fR \fIformula\fR" -Display the source of \fIformula\fR\. +.SS "\fBcat\fR \fIformula\fR|\fIcask\fR" +Display the source of a \fIformula\fR or \fIcask\fR\. +. +.TP +\fB\-\-formula\fR +Treat all named arguments as formulae\. +. +.TP +\fB\-\-cask\fR +Treat all named arguments as casks\. . .SS "\fBcommand\fR \fIcmd\fR" Display the path to the file being used when invoking \fBbrew\fR \fIcmd\fR\.