mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Support casks in brew cat
.
This commit is contained in:
parent
181baaafb0
commit
bc24128263
@ -117,7 +117,7 @@ module Homebrew
|
|||||||
private :to_objects
|
private :to_objects
|
||||||
|
|
||||||
def to_formulae_paths
|
def to_formulae_paths
|
||||||
to_paths(only: :formulae)
|
to_paths(only: :formula)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Keep existing paths and try to convert others to tap, formula or cask paths.
|
# 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|
|
@to_paths[only] ||= downcased_unique_named.flat_map do |name|
|
||||||
if File.exist?(name)
|
if File.exist?(name)
|
||||||
Pathname(name)
|
Pathname(name)
|
||||||
elsif name.count("/") == 1
|
elsif name.count("/") == 1 && !name.start_with?("./", "/")
|
||||||
Tap.fetch(name).path
|
Tap.fetch(name).path
|
||||||
else
|
else
|
||||||
next Formulary.path(name) if only == :formulae
|
next Formulary.path(name) if only == :formula
|
||||||
next Cask::CaskLoader.path(name) if only == :casks
|
next Cask::CaskLoader.path(name) if only == :cask
|
||||||
|
|
||||||
formula_path = Formulary.path(name)
|
formula_path = Formulary.path(name)
|
||||||
cask_path = Cask::CaskLoader.path(name)
|
cask_path = Cask::CaskLoader.path(name)
|
||||||
|
@ -12,18 +12,27 @@ module Homebrew
|
|||||||
def cat_args
|
def cat_args
|
||||||
Homebrew::CLI::Parser.new do
|
Homebrew::CLI::Parser.new do
|
||||||
usage_banner <<~EOS
|
usage_banner <<~EOS
|
||||||
`cat` <formula>
|
`cat` <formula>|<cask>
|
||||||
|
|
||||||
Display the source of <formula>.
|
Display the source of a <formula> or <cask>.
|
||||||
EOS
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
def cat
|
def cat
|
||||||
args = cat_args.parse
|
args = cat_args.parse
|
||||||
|
|
||||||
|
only = :formula if args.formula? && !args.cask?
|
||||||
|
only = :cask if args.cask? && !args.formula?
|
||||||
|
|
||||||
cd HOMEBREW_REPOSITORY
|
cd HOMEBREW_REPOSITORY
|
||||||
pager = if Homebrew::EnvConfig.bat?
|
pager = if Homebrew::EnvConfig.bat?
|
||||||
ENV["BAT_CONFIG_PATH"] = Homebrew::EnvConfig.bat_config_path
|
ENV["BAT_CONFIG_PATH"] = Homebrew::EnvConfig.bat_config_path
|
||||||
@ -31,6 +40,7 @@ module Homebrew
|
|||||||
else
|
else
|
||||||
"cat"
|
"cat"
|
||||||
end
|
end
|
||||||
safe_system pager, args.named.to_formulae_paths.first
|
|
||||||
|
safe_system pager, args.named.to_paths(only: only).first
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -150,16 +150,16 @@ describe Homebrew::CLI::NamedArgs do
|
|||||||
expect(described_class.new("foo", "baz").to_paths).to eq [formula_path, cask_path]
|
expect(described_class.new("foo", "baz").to_paths).to eq [formula_path, cask_path]
|
||||||
end
|
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(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
|
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(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
|
end
|
||||||
end
|
end
|
||||||
|
@ -915,9 +915,14 @@ present, "revision 1" will be added.
|
|||||||
* `--message`:
|
* `--message`:
|
||||||
Append *`message`* to the default commit 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`*
|
### `command` *`cmd`*
|
||||||
|
|
||||||
|
@ -1274,8 +1274,16 @@ Print what would be done rather than doing it\.
|
|||||||
\fB\-\-message\fR
|
\fB\-\-message\fR
|
||||||
Append \fImessage\fR to the default commit message\.
|
Append \fImessage\fR to the default commit message\.
|
||||||
.
|
.
|
||||||
.SS "\fBcat\fR \fIformula\fR"
|
.SS "\fBcat\fR \fIformula\fR|\fIcask\fR"
|
||||||
Display the source of \fIformula\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"
|
.SS "\fBcommand\fR \fIcmd\fR"
|
||||||
Display the path to the file being used when invoking \fBbrew\fR \fIcmd\fR\.
|
Display the path to the file being used when invoking \fBbrew\fR \fIcmd\fR\.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user