Merge pull request #7789 from MLH-Fellowship/cask-integration
Integrate `--cache` and `home` with cask
This commit is contained in:
commit
1dbbb5e58c
@ -16,10 +16,14 @@ module Cask
|
||||
|
||||
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
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
|
||||
require "fetch"
|
||||
require "cli/parser"
|
||||
require "cask/cmd"
|
||||
require "cask/cask_loader"
|
||||
|
||||
module Homebrew
|
||||
module_function
|
||||
@ -19,7 +21,12 @@ module Homebrew
|
||||
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
|
||||
|
||||
@ -28,14 +35,38 @@ module Homebrew
|
||||
|
||||
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
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cli/parser"
|
||||
require "cask/cask_loader"
|
||||
require "cask/exceptions"
|
||||
|
||||
module Homebrew
|
||||
module_function
|
||||
@ -23,7 +25,20 @@ module Homebrew
|
||||
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
|
||||
|
||||
@ -13,4 +13,23 @@ describe "brew --cache", :integration_test do
|
||||
.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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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`*]
|
||||
|
||||
|
||||
@ -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\.
|
||||
.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user