| 
									
										
										
										
											2024-08-10 23:33:58 +01:00
										 |  |  | # typed: strict | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-01 10:15:28 -07:00
										 |  |  | require "abstract_command" | 
					
						
							| 
									
										
										
										
											2018-11-10 22:45:32 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-08 19:13:05 +08:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2024-04-01 10:15:28 -07:00
										 |  |  |   module Cmd | 
					
						
							|  |  |  |     class TapInfo < AbstractCommand | 
					
						
							|  |  |  |       cmd_args do | 
					
						
							|  |  |  |         description <<~EOS | 
					
						
							|  |  |  |           Show detailed information about one or more <tap>s. | 
					
						
							|  |  |  |           If no <tap> names are provided, display brief statistics for all installed taps. | 
					
						
							|  |  |  |         EOS | 
					
						
							|  |  |  |         switch "--installed", | 
					
						
							|  |  |  |                description: "Show information on each installed tap." | 
					
						
							|  |  |  |         flag   "--json", | 
					
						
							|  |  |  |                description: "Print a JSON representation of <tap>. Currently the default and only accepted " \ | 
					
						
							|  |  |  |                             "value for <version> is `v1`. See the docs for examples of using the JSON " \ | 
					
						
							|  |  |  |                             "output: <https://docs.brew.sh/Querying-Brew>" | 
					
						
							| 
									
										
										
										
											2016-09-26 01:44:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-01 10:15:28 -07:00
										 |  |  |         named_args :tap | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2018-11-10 22:45:32 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-01 10:15:28 -07:00
										 |  |  |       sig { override.void } | 
					
						
							|  |  |  |       def run | 
					
						
							| 
									
										
										
										
											2024-07-14 08:49:39 -04:00
										 |  |  |         require "tap" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-01 10:15:28 -07:00
										 |  |  |         taps = if args.installed? | 
					
						
							|  |  |  |           Tap | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           args.named.to_taps | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2018-11-10 22:45:32 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-01 10:15:28 -07:00
										 |  |  |         if args.json | 
					
						
							|  |  |  |           raise UsageError, "invalid JSON version: #{args.json}" unless ["v1", true].include? args.json | 
					
						
							| 
									
										
										
										
											2015-06-08 19:13:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-01 10:15:28 -07:00
										 |  |  |           print_tap_json(taps.sort_by(&:to_s)) | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           print_tap_info(taps.sort_by(&:to_s)) | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2019-03-04 11:59:49 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-01 10:15:28 -07:00
										 |  |  |       private | 
					
						
							| 
									
										
										
										
											2015-06-08 19:13:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-10 23:33:58 +01:00
										 |  |  |       sig { params(taps: T::Array[Tap]).void } | 
					
						
							| 
									
										
										
										
											2024-04-01 10:15:28 -07:00
										 |  |  |       def print_tap_info(taps) | 
					
						
							|  |  |  |         if taps.none? | 
					
						
							|  |  |  |           tap_count = 0
 | 
					
						
							|  |  |  |           formula_count = 0
 | 
					
						
							|  |  |  |           command_count = 0
 | 
					
						
							|  |  |  |           private_count = 0
 | 
					
						
							|  |  |  |           Tap.installed.each do |tap| | 
					
						
							|  |  |  |             tap_count += 1
 | 
					
						
							|  |  |  |             formula_count += tap.formula_files.size | 
					
						
							|  |  |  |             command_count += tap.command_files.size | 
					
						
							|  |  |  |             private_count += 1 if tap.private? | 
					
						
							| 
									
										
										
										
											2015-09-21 14:16:11 +02:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2024-04-01 10:15:28 -07:00
										 |  |  |           info = Utils.pluralize("tap", tap_count, include_count: true) | 
					
						
							|  |  |  |           info += ", #{private_count} private" | 
					
						
							|  |  |  |           info += ", #{Utils.pluralize("formula", formula_count, plural: "e", include_count: true)}" | 
					
						
							|  |  |  |           info += ", #{Utils.pluralize("command", command_count, include_count: true)}" | 
					
						
							| 
									
										
										
										
											2024-08-10 13:35:20 -07:00
										 |  |  |           info += ", #{HOMEBREW_TAP_DIRECTORY.dup.abv}" if HOMEBREW_TAP_DIRECTORY.directory? | 
					
						
							| 
									
										
										
										
											2024-04-01 10:15:28 -07:00
										 |  |  |           puts info | 
					
						
							| 
									
										
										
										
											2015-06-08 19:13:05 +08:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2024-04-01 10:15:28 -07:00
										 |  |  |           info = "" | 
					
						
							|  |  |  |           taps.each_with_index do |tap, i| | 
					
						
							|  |  |  |             puts unless i.zero? | 
					
						
							|  |  |  |             info = "#{tap}: " | 
					
						
							|  |  |  |             if tap.installed? | 
					
						
							| 
									
										
										
										
											2024-04-10 19:02:09 -07:00
										 |  |  |               info += "Installed" | 
					
						
							| 
									
										
										
										
											2024-04-01 10:15:28 -07:00
										 |  |  |               info += if (contents = tap.contents).blank? | 
					
						
							| 
									
										
										
										
											2024-04-12 09:49:33 -07:00
										 |  |  |                 "\nNo commands/casks/formulae" | 
					
						
							| 
									
										
										
										
											2024-04-01 10:15:28 -07:00
										 |  |  |               else | 
					
						
							| 
									
										
										
										
											2024-04-12 09:52:37 -07:00
										 |  |  |                 "\n#{contents.join(", ")}" | 
					
						
							| 
									
										
										
										
											2024-04-01 10:15:28 -07:00
										 |  |  |               end | 
					
						
							| 
									
										
										
										
											2024-04-12 09:52:37 -07:00
										 |  |  |               info += "\nPrivate" if tap.private? | 
					
						
							| 
									
										
										
										
											2024-04-01 10:15:28 -07:00
										 |  |  |               info += "\n#{tap.path} (#{tap.path.abv})" | 
					
						
							|  |  |  |               info += "\nFrom: #{tap.remote.presence || "N/A"}" | 
					
						
							| 
									
										
										
										
											2024-09-30 11:27:35 -04:00
										 |  |  |               info += "\norigin: #{tap.remote}" if tap.remote != tap.default_remote | 
					
						
							|  |  |  |               info += "\nHEAD: #{tap.git_head || "(none)"}" | 
					
						
							|  |  |  |               info += "\nlast commit: #{tap.git_last_commit || "never"}" | 
					
						
							|  |  |  |               info += "\nbranch: #{tap.git_branch || "(none)"}" if tap.git_branch != "master" | 
					
						
							| 
									
										
										
										
											2024-04-01 10:15:28 -07:00
										 |  |  |             else | 
					
						
							|  |  |  |               info += "Not installed" | 
					
						
							|  |  |  |             end | 
					
						
							|  |  |  |             puts info | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2015-06-08 19:13:05 +08:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-10 23:33:58 +01:00
										 |  |  |       sig { params(taps: T::Array[Tap]).void } | 
					
						
							| 
									
										
										
										
											2024-04-01 10:15:28 -07:00
										 |  |  |       def print_tap_json(taps) | 
					
						
							|  |  |  |         puts JSON.pretty_generate(taps.map(&:to_hash)) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2015-06-08 19:13:05 +08:00
										 |  |  |   end | 
					
						
							|  |  |  | end |