2020-10-10 14:16:11 +02:00
|
|
|
# typed: false
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-06-05 23:19:18 -04:00
|
|
|
require "fetch"
|
2019-04-17 18:25:08 +09:00
|
|
|
require "cli/parser"
|
2020-08-10 12:23:32 -04:00
|
|
|
require "cask/download"
|
2014-03-10 14:56:03 -05:00
|
|
|
|
2014-06-18 22:41:47 -05:00
|
|
|
module Homebrew
|
2020-10-20 12:03:48 +02:00
|
|
|
extend T::Sig
|
|
|
|
|
2020-07-23 02:43:22 +02:00
|
|
|
extend Fetch
|
|
|
|
|
2016-09-26 01:44:51 +02:00
|
|
|
module_function
|
|
|
|
|
2020-10-20 12:03:48 +02:00
|
|
|
sig { returns(CLI::Parser) }
|
2019-01-30 21:29:21 +00:00
|
|
|
def __cache_args
|
|
|
|
Homebrew::CLI::Parser.new do
|
|
|
|
usage_banner <<~EOS
|
2020-11-12 10:40:41 -05:00
|
|
|
`--cache` [<options>] [<formula>|<cask>]
|
2019-01-30 21:29:21 +00:00
|
|
|
|
|
|
|
Display Homebrew's download cache. See also `HOMEBREW_CACHE`.
|
|
|
|
|
2020-06-23 11:50:50 -04:00
|
|
|
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."
|
2020-08-07 09:53:30 +01:00
|
|
|
switch "--formula",
|
2020-06-25 12:01:52 -04:00
|
|
|
description: "Only show cache files for formulae."
|
2020-08-07 09:53:30 +01:00
|
|
|
switch "--cask",
|
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"
|
2020-08-07 09:53:30 +01:00
|
|
|
conflicts "--formula", "--cask"
|
2019-01-30 21:29:21 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-11-29 22:34:53 +01:00
|
|
|
sig { void }
|
2010-09-11 20:22:54 +01:00
|
|
|
def __cache
|
2020-07-26 07:24:14 +02:00
|
|
|
args = __cache_args.parse
|
2019-01-30 21:29:21 +00:00
|
|
|
|
2020-03-04 17:28:15 +00:00
|
|
|
if args.no_named?
|
2010-09-11 20:22:54 +01:00
|
|
|
puts HOMEBREW_CACHE
|
2020-08-10 12:23:32 -04:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-12-28 23:14:22 +09:00
|
|
|
formulae_or_casks = args.named.to_formulae_and_casks
|
2020-08-10 12:23:32 -04:00
|
|
|
|
|
|
|
formulae_or_casks.each do |formula_or_cask|
|
|
|
|
if formula_or_cask.is_a? Formula
|
|
|
|
print_formula_cache formula_or_cask, args: args
|
|
|
|
else
|
|
|
|
print_cask_cache formula_or_cask
|
2014-03-10 14:56:03 -05:00
|
|
|
end
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
|
|
|
end
|
2020-06-23 09:30:24 -04:00
|
|
|
|
2020-11-29 22:34:53 +01:00
|
|
|
sig { params(formula: Formula, args: CLI::Args).void }
|
2020-08-10 12:23:32 -04:00
|
|
|
def print_formula_cache(formula, args:)
|
2020-07-26 22:00:38 +02:00
|
|
|
if fetch_bottle?(formula, args: args)
|
2020-06-23 09:30:24 -04:00
|
|
|
puts formula.bottle.cached_download
|
|
|
|
else
|
|
|
|
puts formula.cached_download
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-11-29 22:34:53 +01:00
|
|
|
sig { params(cask: Cask::Cask).void }
|
2020-08-10 12:23:32 -04:00
|
|
|
def print_cask_cache(cask)
|
|
|
|
puts Cask::Download.new(cask).downloader.cached_location
|
2020-06-23 09:30:24 -04:00
|
|
|
end
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|