Merge pull request #8203 from MLH-Fellowship/add-caskroom

caskroom: Add --caskroom to match --cellar
This commit is contained in:
Mike McQuaid 2020-08-04 09:05:08 +01:00 committed by GitHub
commit 9f80629f64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 78 additions and 2 deletions

View File

@ -41,6 +41,7 @@ case "$*" in
--prefix) echo "$HOMEBREW_PREFIX"; exit 0 ;; --prefix) echo "$HOMEBREW_PREFIX"; exit 0 ;;
--cellar) echo "$HOMEBREW_CELLAR"; exit 0 ;; --cellar) echo "$HOMEBREW_CELLAR"; exit 0 ;;
--repository|--repo) echo "$HOMEBREW_REPOSITORY"; exit 0 ;; --repository|--repo) echo "$HOMEBREW_REPOSITORY"; exit 0 ;;
--caskroom) echo "$HOMEBREW_PREFIX/Caskroom"; exit 0 ;;
esac esac
# A depth of 1 means this command was directly invoked by a user. # A depth of 1 means this command was directly invoked by a user.

View File

@ -35,6 +35,7 @@ module Homebrew
@resolved_formulae_casks = nil @resolved_formulae_casks = nil
@formulae_paths = nil @formulae_paths = nil
@casks = nil @casks = nil
@loaded_casks = nil
@kegs = nil @kegs = nil
@kegs_casks = nil @kegs_casks = nil
@ -125,6 +126,10 @@ module Homebrew
.freeze .freeze
end end
def loaded_casks
@loaded_casks ||= downcased_unique_named.map(&Cask::CaskLoader.method(:load)).freeze
end
def kegs def kegs
@kegs ||= downcased_unique_named.map do |name| @kegs ||= downcased_unique_named.map do |name|
resolve_keg name resolve_keg name

View File

@ -0,0 +1,30 @@
# frozen_string_literal: true
module Homebrew
module_function
def __caskroom_args
Homebrew::CLI::Parser.new do
usage_banner <<~EOS
`--caskroom` [<cask>]
Display Homebrew's Caskroom path.
If <cask> is provided, display the location in the Caskroom where <cask>
would be installed, without any sort of versioned directory as the last path.
EOS
end
end
def __caskroom
args = __caskroom_args.parse
if args.loaded_casks.blank?
puts Cask::Caskroom.path
else
args.loaded_casks.each do |cask|
puts "#{Cask::Caskroom.path}/#{cask.token}"
end
end
end
end

View File

@ -0,0 +1,26 @@
# frozen_string_literal: true
describe "brew --caskroom", :integration_test do
let(:local_transmission) {
Cask::CaskLoader.load(cask_path("local-transmission"))
}
let(:local_caffeine) {
Cask::CaskLoader.load(cask_path("local-caffeine"))
}
it "outputs Homebrew's caskroom" do
expect { brew "--caskroom" }
.to output("#{HOMEBREW_PREFIX/"Caskroom"}\n").to_stdout
.and not_to_output.to_stderr
.and be_a_success
end
it "outputs the caskroom path of casks" do
expect { brew "--caskroom", cask_path("local-transmission"), cask_path("local-caffeine") }
.to output("#{HOMEBREW_PREFIX/"Caskroom"/"local-transmission"}\n" \
"#{HOMEBREW_PREFIX/"Caskroom"/"local-caffeine\n"}").to_stdout
.and not_to_output.to_stderr
.and be_a_success
end
end

View File

@ -1,4 +1,5 @@
--cache --cache
--caskroom
--cellar --cellar
--config --config
--env --env

View File

@ -610,6 +610,13 @@ If *`formula`* is provided, display the file or directory used to cache *`formul
* `--cask`: * `--cask`:
Only show cache files for casks. Only show cache files for casks.
### `--caskroom` [*`cask`*]
Display Homebrew's Caskroom path.
If *`cask`* is provided, display the location in the Caskroom where *`cask`* would
be installed, without any sort of versioned directory as the last path.
### `--cellar` [*`formula`*] ### `--cellar` [*`formula`*]
Display Homebrew's Cellar path. *Default:* `$(brew --prefix)/Cellar`, or if that Display Homebrew's Cellar path. *Default:* `$(brew --prefix)/Cellar`, or if that

View File

@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3 .\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3
. .
.TH "BREW\-CASK" "1" "July 2020" "Homebrew" "brew-cask" .TH "BREW\-CASK" "1" "August 2020" "Homebrew" "brew-cask"
. .
.SH "NAME" .SH "NAME"
\fBbrew\-cask\fR \- a friendly binary installer for macOS \fBbrew\-cask\fR \- a friendly binary installer for macOS

View File

@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3 .\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3
. .
.TH "BREW" "1" "July 2020" "Homebrew" "brew" .TH "BREW" "1" "August 2020" "Homebrew" "brew"
. .
.SH "NAME" .SH "NAME"
\fBbrew\fR \- The Missing Package Manager for macOS \fBbrew\fR \- The Missing Package Manager for macOS
@ -807,6 +807,12 @@ Only show cache files for formulae\.
\fB\-\-cask\fR \fB\-\-cask\fR
Only show cache files for casks\. Only show cache files for casks\.
. .
.SS "\fB\-\-caskroom\fR [\fIcask\fR]"
Display Homebrew\'s Caskroom path\.
.
.P
If \fIcask\fR is provided, display the location in the Caskroom where \fIcask\fR would be installed, without any sort of versioned directory as the last path\.
.
.SS "\fB\-\-cellar\fR [\fIformula\fR]" .SS "\fB\-\-cellar\fR [\fIformula\fR]"
Display Homebrew\'s Cellar path\. \fIDefault:\fR \fB$(brew \-\-prefix)/Cellar\fR, or if that directory doesn\'t exist, \fB$(brew \-\-repository)/Cellar\fR\. Display Homebrew\'s Cellar path\. \fIDefault:\fR \fB$(brew \-\-prefix)/Cellar\fR, or if that directory doesn\'t exist, \fB$(brew \-\-repository)/Cellar\fR\.
. .