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

76 lines
2.2 KiB
Ruby
Raw Normal View History

2023-03-06 09:49:53 -08:00
# typed: true
# frozen_string_literal: true
require "fetch"
2019-04-17 18:25:08 +09:00
require "cli/parser"
require "cask/download"
module Homebrew
extend Fetch
2020-10-20 12:03:48 +02:00
sig { returns(CLI::Parser) }
2023-03-06 09:49:53 -08:00
def self.__cache_args
2019-01-30 21:29:21 +00:00
Homebrew::CLI::Parser.new do
description <<~EOS
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."
flag "--bottle-tag=",
2021-08-26 14:37:27 -07:00
description: "Show the cache file used when pouring a bottle for the given tag."
2021-08-23 20:37:02 -07:00
switch "--HEAD",
description: "Show the cache file used when building from HEAD."
switch "--formula", "--formulae",
2020-06-25 12:01:52 -04:00
description: "Only show cache files for formulae."
switch "--cask", "--casks",
2020-06-25 12:01:52 -04:00
description: "Only show cache files for casks."
2020-11-27 11:41:08 -05:00
2021-08-26 14:37:27 -07:00
conflicts "--build-from-source", "--force-bottle", "--bottle-tag", "--HEAD", "--cask"
conflicts "--formula", "--cask"
2021-01-10 14:26:40 -05:00
named_args [:formula, :cask]
2019-01-30 21:29:21 +00:00
end
end
2020-11-29 22:34:53 +01:00
sig { void }
2023-03-06 09:49:53 -08:00
def self.__cache
args = __cache_args.parse
2019-01-30 21:29:21 +00:00
if args.no_named?
puts HOMEBREW_CACHE
return
end
2020-12-28 23:14:22 +09:00
formulae_or_casks = args.named.to_formulae_and_casks
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
end
end
end
2020-11-29 22:34:53 +01:00
sig { params(formula: Formula, args: CLI::Args).void }
2023-03-06 09:49:53 -08:00
def self.print_formula_cache(formula, args:)
if fetch_bottle?(formula, force_bottle: args.force_bottle?, bottle_tag: args.bottle_tag&.to_sym,
build_from_source_formulae: args.build_from_source_formulae)
2023-03-06 09:49:53 -08:00
puts formula.bottle_for_tag(args.bottle_tag&.to_sym)&.cached_download
2021-08-23 20:37:02 -07:00
elsif args.HEAD?
puts formula.head.cached_download
else
puts formula.cached_download
end
end
2020-11-29 22:34:53 +01:00
sig { params(cask: Cask::Cask).void }
2023-03-06 09:49:53 -08:00
def self.print_cask_cache(cask)
puts Cask::Download.new(cask).downloader.cached_location
end
end