cache: Add flags for printing only formulae or casks
This commit is contained in:
parent
78ccb05166
commit
11fbf9d035
@ -11,17 +11,22 @@ module Homebrew
|
|||||||
def __cache_args
|
def __cache_args
|
||||||
Homebrew::CLI::Parser.new do
|
Homebrew::CLI::Parser.new do
|
||||||
usage_banner <<~EOS
|
usage_banner <<~EOS
|
||||||
`--cache` [<options>] [<formula>]
|
`--cache` [<options>] [<formula/cask>]
|
||||||
|
|
||||||
Display Homebrew's download cache. See also `HOMEBREW_CACHE`.
|
Display Homebrew's download cache. See also `HOMEBREW_CACHE`.
|
||||||
|
|
||||||
If <formula> is provided, display the file or directory used to cache <formula>.
|
If <formula/cask> is provided, display the file or directory used to cache <formula/cask>.
|
||||||
EOS
|
EOS
|
||||||
switch "-s", "--build-from-source",
|
switch "-s", "--build-from-source",
|
||||||
description: "Show the cache file used when building from source."
|
description: "Show the cache file used when building from source."
|
||||||
switch "--force-bottle",
|
switch "--force-bottle",
|
||||||
description: "Show the cache file used when pouring a 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 "--build-from-source", "--force-bottle"
|
||||||
|
conflicts "--formula", "--cask"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -30,26 +35,39 @@ module Homebrew
|
|||||||
|
|
||||||
if args.no_named?
|
if args.no_named?
|
||||||
puts HOMEBREW_CACHE
|
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
|
else
|
||||||
args.named.each do |name|
|
args.named.each do |name|
|
||||||
|
print_formula_cache name
|
||||||
|
rescue FormulaUnavailableError => e
|
||||||
|
begin
|
||||||
|
print_cask_cache name
|
||||||
|
rescue Cask::CaskUnavailableError => e
|
||||||
|
odie "No available formula or cask with the name \"#{name}\""
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def print_formula_cache(name)
|
||||||
formula = Formulary.factory name
|
formula = Formulary.factory name
|
||||||
if Fetch.fetch_bottle?(formula)
|
if Fetch.fetch_bottle?(formula)
|
||||||
puts formula.bottle.cached_download
|
puts formula.bottle.cached_download
|
||||||
else
|
else
|
||||||
puts formula.cached_download
|
puts formula.cached_download
|
||||||
end
|
end
|
||||||
rescue FormulaUnavailableError => e
|
end
|
||||||
formula_error_message = e.message
|
|
||||||
begin
|
def print_cask_cache(name)
|
||||||
cask = Cask::CaskLoader.load name
|
cask = Cask::CaskLoader.load name
|
||||||
puts "cask: #{Cask::Cmd::Cache.cached_location(cask)}"
|
puts Cask::Cmd::Cache.cached_location(cask)
|
||||||
rescue Cask::CaskUnavailableError => e
|
|
||||||
cask_error_message = e.message
|
|
||||||
odie "No available formula or cask with the name \"#{name}\"\n" \
|
|
||||||
"#{formula_error_message}\n" \
|
|
||||||
"#{cask_error_message}\n"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user