diff --git a/Library/Homebrew/cli/args.rb b/Library/Homebrew/cli/args.rb index 1253c71b0c..f9d7adef1f 100644 --- a/Library/Homebrew/cli/args.rb +++ b/Library/Homebrew/cli/args.rb @@ -35,6 +35,7 @@ module Homebrew @resolved_formulae_casks = nil @formulae_paths = nil @casks = nil + @loaded_casks = nil @kegs = nil @kegs_casks = nil @@ -125,6 +126,10 @@ module Homebrew .freeze end + def loaded_casks + @loaded_casks ||= downcased_unique_named.map(&Cask::CaskLoader.method(:load)).freeze + end + def kegs @kegs ||= downcased_unique_named.map do |name| resolve_keg name diff --git a/Library/Homebrew/cmd/--caskroom.rb b/Library/Homebrew/cmd/--caskroom.rb new file mode 100644 index 0000000000..dba8debb51 --- /dev/null +++ b/Library/Homebrew/cmd/--caskroom.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +module Homebrew + module_function + + def __caskroom_args + Homebrew::CLI::Parser.new do + usage_banner <<~EOS + `--caskroom` [] + + Display Homebrew's Caskroom path. + + If is provided, display the location in the Caskroom where + 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 diff --git a/Library/Homebrew/test/cmd/--caskroom_spec.rb b/Library/Homebrew/test/cmd/--caskroom_spec.rb new file mode 100644 index 0000000000..058573ac02 --- /dev/null +++ b/Library/Homebrew/test/cmd/--caskroom_spec.rb @@ -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 diff --git a/completions/internal_commands_list.txt b/completions/internal_commands_list.txt index aeb66a2818..f768c56229 100644 --- a/completions/internal_commands_list.txt +++ b/completions/internal_commands_list.txt @@ -1,4 +1,5 @@ --cache +--caskroom --cellar --config --env diff --git a/docs/Manpage.md b/docs/Manpage.md index ba63f33318..f7e051a7b4 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -610,6 +610,13 @@ If *`formula`* is provided, display the file or directory used to cache *`formul * `--cask`: 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`*] Display Homebrew's Cellar path. *Default:* `$(brew --prefix)/Cellar`, or if that diff --git a/manpages/brew-cask.1 b/manpages/brew-cask.1 index f00c80f3ed..f35a505d79 100644 --- a/manpages/brew-cask.1 +++ b/manpages/brew-cask.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.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" \fBbrew\-cask\fR \- a friendly binary installer for macOS diff --git a/manpages/brew.1 b/manpages/brew.1 index 277ff7733d..0278f39a0e 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.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" \fBbrew\fR \- The Missing Package Manager for macOS @@ -807,6 +807,12 @@ Only show cache files for formulae\. \fB\-\-cask\fR 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]" Display Homebrew\'s Cellar path\. \fIDefault:\fR \fB$(brew \-\-prefix)/Cellar\fR, or if that directory doesn\'t exist, \fB$(brew \-\-repository)/Cellar\fR\. .