brew/Library/Homebrew/cmd/--cache.rb

75 lines
2.0 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
require "fetch"
2019-04-17 18:25:08 +09:00
require "cli/parser"
require "cask/cmd"
require "cask/cask_loader"
module Homebrew
extend Fetch
2016-09-26 01:44:51 +02:00
module_function
2019-01-30 21:29:21 +00:00
def __cache_args
Homebrew::CLI::Parser.new do
usage_banner <<~EOS
`--cache` [<options>] [<formula|cask>]
2019-01-30 21:29:21 +00:00
Display Homebrew's download cache. See also `HOMEBREW_CACHE`.
If <formula> is provided, display the file or directory used to cache <formula>.
2019-01-30 21:29:21 +00:00
EOS
switch "-s", "--build-from-source",
2019-04-30 08:44:35 +01:00
description: "Show the cache file used when building from source."
2019-01-30 21:29:21 +00:00
switch "--force-bottle",
2019-04-30 08:44:35 +01:00
description: "Show the cache file used when pouring a bottle."
switch "--formulae",
2020-06-25 12:01:52 -04:00
description: "Only show cache files for formulae."
switch "--casks",
2020-06-25 12:01:52 -04:00
description: "Only show cache files for casks."
2019-01-30 21:29:21 +00:00
conflicts "--build-from-source", "--force-bottle"
conflicts "--formulae", "--casks"
2019-01-30 21:29:21 +00:00
end
end
def __cache
args = __cache_args.parse
2019-01-30 21:29:21 +00:00
if args.no_named?
puts HOMEBREW_CACHE
elsif args.formulae?
args.named.each do |name|
print_formula_cache name, args: args
end
elsif args.casks?
args.named.each do |name|
print_cask_cache name
end
else
args.named.each do |name|
print_formula_cache name, args: args
2020-06-23 09:50:45 -04:00
rescue FormulaUnavailableError
begin
print_cask_cache name
2020-06-23 09:50:45 -04:00
rescue Cask::CaskUnavailableError
odie "No available formula or cask with the name \"#{name}\""
end
end
end
end
def print_formula_cache(name, args:)
formula = Formulary.factory(name, force_bottle: args.force_bottle?, flags: args.flags_only)
if fetch_bottle?(formula, args: args)
puts formula.bottle.cached_download
else
puts formula.cached_download
end
end
def print_cask_cache(name)
2020-06-23 09:50:45 -04:00
cask = Cask::CaskLoader.load name
puts Cask::Cmd::Cache.cached_location(cask)
end
end