| 
									
										
										
										
											2020-10-10 14:16:11 +02:00
										 |  |  | # typed: false | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 18:25:08 +09:00
										 |  |  | require "cli/parser" | 
					
						
							| 
									
										
										
										
											2018-11-10 22:45:32 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-08 19:13:05 +08:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   extend T::Sig | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-26 01:44:51 +02:00
										 |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   sig { returns(CLI::Parser) } | 
					
						
							| 
									
										
										
										
											2018-11-10 22:45:32 +05:30
										 |  |  |   def tap_info_args | 
					
						
							|  |  |  |     Homebrew::CLI::Parser.new do | 
					
						
							|  |  |  |       usage_banner <<~EOS | 
					
						
							| 
									
										
										
										
											2019-01-30 21:32:35 +00:00
										 |  |  |         `tap-info` [<options>] [<tap>] | 
					
						
							| 
									
										
										
										
											2018-11-10 22:45:32 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-20 00:04:14 -04:00
										 |  |  |         Show detailed information about one or more <tap>s. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         If no <tap> names are provided, display brief statistics for all installed taps. | 
					
						
							| 
									
										
										
										
											2018-11-10 22:45:32 +05:30
										 |  |  |       EOS | 
					
						
							|  |  |  |       switch "--installed", | 
					
						
							| 
									
										
										
										
											2019-08-20 00:04:14 -04:00
										 |  |  |              description: "Show information on each installed tap." | 
					
						
							| 
									
										
										
										
											2019-08-06 13:23:19 -04:00
										 |  |  |       flag   "--json", | 
					
						
							| 
									
										
										
										
											2019-08-19 22:44:50 -04:00
										 |  |  |              description: "Print a JSON representation of <tap>. Currently the default and only accepted "\ | 
					
						
							| 
									
										
										
										
											2019-08-06 13:23:19 -04:00
										 |  |  |                           "value for <version> is `v1`. See the docs for examples of using the JSON "\ | 
					
						
							|  |  |  |                           "output: <https://docs.brew.sh/Querying-Brew>" | 
					
						
							| 
									
										
										
										
											2018-11-10 22:45:32 +05:30
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-08 19:13:05 +08:00
										 |  |  |   def tap_info | 
					
						
							| 
									
										
										
										
											2020-07-30 18:40:10 +02:00
										 |  |  |     args = tap_info_args.parse | 
					
						
							| 
									
										
										
										
											2018-11-10 22:45:32 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-13 21:15:06 +00:00
										 |  |  |     taps = if args.installed? | 
					
						
							|  |  |  |       Tap | 
					
						
							| 
									
										
										
										
											2015-06-08 19:13:05 +08:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2020-03-13 21:15:06 +00:00
										 |  |  |       args.named.sort.map do |name| | 
					
						
							| 
									
										
										
										
											2015-12-07 14:11:04 +08:00
										 |  |  |         Tap.fetch(name) | 
					
						
							| 
									
										
										
										
											2015-06-08 19:13:05 +08:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-04 11:59:49 -05:00
										 |  |  |     if args.json | 
					
						
							| 
									
										
										
										
											2020-03-04 17:28:15 +00:00
										 |  |  |       raise UsageError, "invalid JSON version: #{args.json}" unless ["v1", true].include? args.json | 
					
						
							| 
									
										
										
										
											2019-03-04 11:59:49 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-28 14:56:51 +05:30
										 |  |  |       print_tap_json(taps.sort_by(&:to_s)) | 
					
						
							| 
									
										
										
										
											2015-06-08 19:13:05 +08:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2017-10-28 14:56:51 +05:30
										 |  |  |       print_tap_info(taps.sort_by(&:to_s)) | 
					
						
							| 
									
										
										
										
											2015-06-08 19:13:05 +08:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def print_tap_info(taps) | 
					
						
							|  |  |  |     if taps.none? | 
					
						
							|  |  |  |       tap_count = 0
 | 
					
						
							|  |  |  |       formula_count = 0
 | 
					
						
							|  |  |  |       command_count = 0
 | 
					
						
							| 
									
										
										
										
											2015-07-22 18:07:30 +08:00
										 |  |  |       pinned_count = 0
 | 
					
						
							| 
									
										
										
										
											2016-07-10 02:27:59 +02:00
										 |  |  |       private_count = 0
 | 
					
						
							| 
									
										
										
										
											2015-06-08 19:13:05 +08:00
										 |  |  |       Tap.each do |tap| | 
					
						
							|  |  |  |         tap_count += 1
 | 
					
						
							|  |  |  |         formula_count += tap.formula_files.size | 
					
						
							|  |  |  |         command_count += tap.command_files.size | 
					
						
							| 
									
										
										
										
											2015-07-22 18:07:30 +08:00
										 |  |  |         pinned_count += 1 if tap.pinned? | 
					
						
							| 
									
										
										
										
											2016-07-10 02:27:59 +02:00
										 |  |  |         private_count += 1 if tap.private? | 
					
						
							| 
									
										
										
										
											2015-06-08 19:13:05 +08:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2018-09-17 20:11:11 +02:00
										 |  |  |       info = "#{tap_count} #{"tap".pluralize(tap_count)}" | 
					
						
							| 
									
										
										
										
											2015-07-22 18:07:30 +08:00
										 |  |  |       info += ", #{pinned_count} pinned" | 
					
						
							| 
									
										
										
										
											2016-07-10 02:27:59 +02:00
										 |  |  |       info += ", #{private_count} private" | 
					
						
							| 
									
										
										
										
											2018-09-17 20:11:11 +02:00
										 |  |  |       info += ", #{formula_count} #{"formula".pluralize(formula_count)}" | 
					
						
							|  |  |  |       info += ", #{command_count} #{"command".pluralize(command_count)}" | 
					
						
							| 
									
										
										
										
											2019-05-04 09:09:58 -07:00
										 |  |  |       info += ", #{Tap::TAP_DIRECTORY.dup.abv}" if Tap::TAP_DIRECTORY.directory? | 
					
						
							| 
									
										
										
										
											2015-06-08 19:13:05 +08:00
										 |  |  |       puts info | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       taps.each_with_index do |tap, i| | 
					
						
							| 
									
										
										
										
											2016-09-10 10:24:57 +01:00
										 |  |  |         puts unless i.zero? | 
					
						
							| 
									
										
										
										
											2015-06-08 19:13:05 +08:00
										 |  |  |         info = "#{tap}: " | 
					
						
							|  |  |  |         if tap.installed? | 
					
						
							| 
									
										
										
										
											2020-08-06 14:00:56 +01:00
										 |  |  |           info += if (contents = tap.contents).blank? | 
					
						
							|  |  |  |             "no commands/casks/formulae" | 
					
						
							| 
									
										
										
										
											2018-06-20 20:35:24 +02:00
										 |  |  |           else | 
					
						
							| 
									
										
										
										
											2020-08-06 14:00:56 +01:00
										 |  |  |             contents.join(", ") | 
					
						
							| 
									
										
										
										
											2015-09-21 14:16:11 +02:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2020-08-06 14:00:56 +01:00
										 |  |  |           info += ", private" if tap.private? | 
					
						
							| 
									
										
										
										
											2015-06-08 19:13:05 +08:00
										 |  |  |           info += "\n#{tap.path} (#{tap.path.abv})" | 
					
						
							| 
									
										
										
										
											2020-12-01 17:04:59 +00:00
										 |  |  |           info += "\nFrom: #{tap.remote.presence || "N/A"}" | 
					
						
							| 
									
										
										
										
											2015-06-08 19:13:05 +08:00
										 |  |  |         else | 
					
						
							|  |  |  |           info += "Not installed" | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |         puts info | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def print_tap_json(taps) | 
					
						
							| 
									
										
										
										
											2016-11-20 13:00:01 -05:00
										 |  |  |     puts JSON.generate(taps.map(&:to_hash)) | 
					
						
							| 
									
										
										
										
											2015-06-08 19:13:05 +08:00
										 |  |  |   end | 
					
						
							|  |  |  | end |