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

72 lines
1.7 KiB
Ruby
Raw Normal View History

2020-10-10 14:16:11 +02:00
# typed: false
# frozen_string_literal: true
require "fetch"
2019-04-17 18:25:08 +09:00
require "cli/parser"
require "cask/download"
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 "--formula",
2020-06-25 12:01:52 -04:00
description: "Only show cache files for formulae."
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"
conflicts "--formula", "--cask"
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
return
end
formulae_or_casks = if args.formula?
args.named.to_formulae
elsif args.cask?
args.named.to_casks
else
args.named.to_formulae_and_casks
end
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
def print_formula_cache(formula, args:)
if fetch_bottle?(formula, args: args)
puts formula.bottle.cached_download
else
puts formula.cached_download
end
end
def print_cask_cache(cask)
puts Cask::Download.new(cask).downloader.cached_location
end
end