| 
									
										
										
										
											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-06-19 10:37:31 -04:00
										 |  |  | require "cask/cmd" | 
					
						
							| 
									
										
										
										
											2020-06-19 14:00:26 -04:00
										 |  |  | require "cask/cask_loader" | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:03 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 22:41:47 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2020-06-23 11:50:50 -04:00
										 |  |  |         `--cache` [<options>] [<formula>] | 
					
						
							| 
									
										
										
										
											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-06-23 09:30:24 -04:00
										 |  |  |       switch "--formula", | 
					
						
							| 
									
										
										
										
											2020-06-25 12:01:52 -04:00
										 |  |  |              description: "Only show cache files for formulae." | 
					
						
							| 
									
										
										
										
											2020-06-23 09:30:24 -04: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-06-23 09:30:24 -04:00
										 |  |  |       conflicts "--formula", "--cask" | 
					
						
							| 
									
										
										
										
											2019-01-30 21:29:21 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |   def __cache | 
					
						
							| 
									
										
										
										
											2019-01-30 21:29:21 +00:00
										 |  |  |     __cache_args.parse | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-04 17:28:15 +00:00
										 |  |  |     if args.no_named? | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |       puts HOMEBREW_CACHE | 
					
						
							| 
									
										
										
										
											2020-06-23 09:30:24 -04:00
										 |  |  |     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 | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2020-06-19 14:00:26 -04:00
										 |  |  |       args.named.each do |name| | 
					
						
							| 
									
										
										
										
											2020-06-23 09:30:24 -04:00
										 |  |  |         print_formula_cache name | 
					
						
							| 
									
										
										
										
											2020-06-23 09:50:45 -04:00
										 |  |  |       rescue FormulaUnavailableError | 
					
						
							| 
									
										
										
										
											2020-06-19 14:00:26 -04:00
										 |  |  |         begin | 
					
						
							| 
									
										
										
										
											2020-06-23 09:30:24 -04:00
										 |  |  |           print_cask_cache name | 
					
						
							| 
									
										
										
										
											2020-06-23 09:50:45 -04:00
										 |  |  |         rescue Cask::CaskUnavailableError | 
					
						
							| 
									
										
										
										
											2020-06-23 09:30:24 -04:00
										 |  |  |           odie "No available formula or cask with the name \"#{name}\"" | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:03 -05:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2020-06-23 09:30:24 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def print_formula_cache(name) | 
					
						
							|  |  |  |     formula = Formulary.factory name | 
					
						
							|  |  |  |     if Fetch.fetch_bottle?(formula) | 
					
						
							|  |  |  |       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) | 
					
						
							| 
									
										
										
										
											2020-06-23 09:30:24 -04:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | end |