Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate --cache and home with cask #7789

Merged
merged 19 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Library/Homebrew/cask/cmd/--cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ def initialize(*)

def run
casks.each do |cask|
puts Download.new(cask).downloader.cached_location
puts self.class.cached_location(cask)
end
end

def self.cached_location(cask)
Download.new(cask).downloader.cached_location
end

def self.help
"display the file used to cache the Cask"
end
Expand Down
41 changes: 36 additions & 5 deletions Library/Homebrew/cmd/--cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

require "fetch"
require "cli/parser"
require "cask/cmd"
require "cask/cask_loader"

module Homebrew
module_function
Expand All @@ -19,7 +21,12 @@ def __cache_args
description: "Show the cache file used when building from source."
switch "--force-bottle",
description: "Show the cache file used when pouring a bottle."
switch "--formula",
description: "Show cache files for only formulae"
switch "--cask",
description: "Show cache files for only casks"
conflicts "--build-from-source", "--force-bottle"
conflicts "--formula", "--cask"
end
end

Expand All @@ -28,14 +35,38 @@ def __cache

if args.no_named?
puts HOMEBREW_CACHE
elsif args.formula?
args.named.each do |name|
print_formula_cache name
end
elsif args.cask?
args.named.each do |name|
print_cask_cache name
end
else
args.formulae.each do |f|
if Fetch.fetch_bottle?(f)
puts f.bottle.cached_download
else
puts f.cached_download
args.named.each do |name|
print_formula_cache name
rescue FormulaUnavailableError
begin
print_cask_cache name
rescue Cask::CaskUnavailableError
odie "No available formula or cask with the name \"#{name}\""
end
end
end
end

def print_formula_cache(name)
formula = Formulary.factory name
if Fetch.fetch_bottle?(formula)
puts formula.bottle.cached_download
else
puts formula.cached_download
end
end

def print_cask_cache(name)
cask = Cask::CaskLoader.load name
puts Cask::Cmd::Cache.cached_location(cask)
end
end
17 changes: 16 additions & 1 deletion Library/Homebrew/cmd/home.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

require "cli/parser"
require "cask/cask_loader"
require "cask/exceptions"

module Homebrew
module_function
Expand All @@ -23,7 +25,20 @@ def home
if args.no_named?
exec_browser HOMEBREW_WWW
else
exec_browser(*args.formulae.map(&:homepage))
homepages = args.named.map do |name|
f = Formulary.factory(name)
puts "Opening homepage for formula #{name}"
f.homepage
rescue FormulaUnavailableError
begin
c = Cask::CaskLoader.load(name)
puts "Opening homepage for cask #{name}"
c.homepage
rescue Cask::CaskUnavailableError
odie "No available formula or cask with the name \"#{name}\""
end
end
exec_browser(*homepages)
end
end
end
19 changes: 19 additions & 0 deletions Library/Homebrew/test/cmd/--cache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,23 @@
.and not_to_output.to_stderr
.and be_a_success
end

it "prints the cache files for a given Cask" do
expect { brew "--cache", cask_path("local-caffeine") }
.to output(%r{#{HOMEBREW_CACHE}/downloads/[\da-f]{64}--caffeine\.zip}).to_stdout
.and not_to_output.to_stderr
.and be_a_success
end

it "prints the cache files for a given Formula and Cask" do
expect { brew "--cache", testball, cask_path("local-caffeine") }
.to output(
%r{
#{HOMEBREW_CACHE}/downloads/[\da-f]{64}--testball-.*\n
#{HOMEBREW_CACHE}/downloads/[\da-f]{64}--caffeine\.zip
}x,
).to_stdout
.and not_to_output.to_stderr
.and be_a_success
end
end
31 changes: 30 additions & 1 deletion Library/Homebrew/test/cmd/home_spec.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,46 @@
# frozen_string_literal: true

require "cmd/shared_examples/args_parse"
require "support/lib/config"

describe "Homebrew.home_args" do
it_behaves_like "parseable arguments"
end

describe "brew home", :integration_test do
let(:testballhome_homepage) {
Formula["testballhome"].homepage
}

let(:local_caffeine_path) {
cask_path("local-caffeine")
}

let(:local_caffeine_homepage) {
Cask::CaskLoader.load(local_caffeine_path).homepage
}

it "opens the homepage for a given Formula" do
setup_test_formula "testballhome"

expect { brew "home", "testballhome", "HOMEBREW_BROWSER" => "echo" }
.to output("#{Formula["testballhome"].homepage}\n").to_stdout
.to output(/#{testballhome_homepage}/).to_stdout
.and not_to_output.to_stderr
.and be_a_success
end

it "opens the homepage for a given Cask" do
expect { brew "home", cask_path("local-caffeine"), "HOMEBREW_BROWSER" => "echo" }
.to output(/#{local_caffeine_homepage}/).to_stdout
.and not_to_output.to_stderr
.and be_a_success
end

it "opens the homepages for a given formula and Cask" do
setup_test_formula "testballhome"

expect { brew "home", "testballhome", cask_path("local-caffeine"), "HOMEBREW_BROWSER" => "echo" }
.to output(/#{testballhome_homepage} #{local_caffeine_homepage}/).to_stdout
.and not_to_output.to_stderr
.and be_a_success
end
Expand Down
4 changes: 4 additions & 0 deletions docs/Manpage.md
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,10 @@ If *`formula`* is provided, display the file or directory used to cache *`formul
Show the cache file used when building from source.
* `--force-bottle`:
Show the cache file used when pouring a bottle.
* `--formula`:
Show cache files for only formulae
* `--cask`:
Show cache files for only casks

### `--cellar` [*`formula`*]

Expand Down
8 changes: 8 additions & 0 deletions manpages/brew.1
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,14 @@ Show the cache file used when building from source\.
\fB\-\-force\-bottle\fR
Show the cache file used when pouring a bottle\.
.
.TP
\fB\-\-formula\fR
Show cache files for only formulae
.
.TP
\fB\-\-cask\fR
Show cache files for only casks
.
.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\.
.
Expand Down