| 
									
										
										
										
											2016-07-10 02:27:13 +02:00
										 |  |  | #:  * `tap-info`: | 
					
						
							|  |  |  | #:    Display a brief summary of all installed taps. | 
					
						
							|  |  |  | #: | 
					
						
							|  |  |  | #:  * `tap-info` (`--installed`|<taps>): | 
					
						
							|  |  |  | #:    Display detailed information about one or more <taps>. | 
					
						
							|  |  |  | #: | 
					
						
							|  |  |  | #:    Pass `--installed` to display information on all installed taps. | 
					
						
							| 
									
										
										
										
											2016-04-08 16:28:43 +02:00
										 |  |  | #: | 
					
						
							|  |  |  | #:  * `tap-info` `--json=`<version> (`--installed`|<taps>): | 
					
						
							|  |  |  | #:    Print a JSON representation of <taps>. Currently the only accepted value | 
					
						
							|  |  |  | #:    for <version> is `v1`. | 
					
						
							|  |  |  | #: | 
					
						
							|  |  |  | #:    Pass `--installed` to get information on installed taps. | 
					
						
							|  |  |  | #: | 
					
						
							| 
									
										
										
										
											2017-02-25 17:37:57 -05:00
										 |  |  | #:    See the docs for examples of using the JSON output: | 
					
						
							| 
									
										
										
										
											2017-07-27 15:59:37 +01:00
										 |  |  | #:    <https://docs.brew.sh/Querying-Brew.html> | 
					
						
							| 
									
										
										
										
											2016-04-08 16:28:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-07 14:11:04 +08:00
										 |  |  | require "tap" | 
					
						
							| 
									
										
										
										
											2015-06-08 19:13:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2016-09-26 01:44:51 +02:00
										 |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-08 19:13:05 +08:00
										 |  |  |   def tap_info | 
					
						
							|  |  |  |     if ARGV.include? "--installed" | 
					
						
							|  |  |  |       taps = Tap | 
					
						
							|  |  |  |     else | 
					
						
							| 
									
										
										
										
											2017-10-14 05:47:17 +01:00
										 |  |  |       taps = ARGV.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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ARGV.json == "v1" | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2017-03-11 11:33:12 +01:00
										 |  |  |       info = Formatter.pluralize(tap_count, "tap").to_s | 
					
						
							| 
									
										
										
										
											2015-07-22 18:07:30 +08:00
										 |  |  |       info += ", #{pinned_count} pinned" | 
					
						
							| 
									
										
										
										
											2016-07-10 02:27:59 +02:00
										 |  |  |       info += ", #{private_count} private" | 
					
						
							| 
									
										
										
										
											2017-03-11 11:33:12 +01:00
										 |  |  |       info += ", #{Formatter.pluralize(formula_count, "formula")}" | 
					
						
							|  |  |  |       info += ", #{Formatter.pluralize(command_count, "command")}" | 
					
						
							| 
									
										
										
										
											2015-06-08 19:13:05 +08:00
										 |  |  |       info += ", #{Tap::TAP_DIRECTORY.abv}" if Tap::TAP_DIRECTORY.directory? | 
					
						
							|  |  |  |       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? | 
					
						
							| 
									
										
										
										
											2015-09-21 14:16:11 +02:00
										 |  |  |           info += tap.pinned? ? "pinned" : "unpinned" | 
					
						
							| 
									
										
										
										
											2016-07-10 02:27:59 +02:00
										 |  |  |           info += ", private" if tap.private? | 
					
						
							| 
									
										
										
										
											2017-09-24 20:12:58 +01:00
										 |  |  |           if (formula_count = tap.formula_files.size).positive? | 
					
						
							| 
									
										
										
										
											2017-03-11 11:33:12 +01:00
										 |  |  |             info += ", #{Formatter.pluralize(formula_count, "formula")}" | 
					
						
							| 
									
										
										
										
											2015-09-21 14:16:11 +02:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2017-09-24 20:12:58 +01:00
										 |  |  |           if (command_count = tap.command_files.size).positive? | 
					
						
							| 
									
										
										
										
											2017-03-11 11:33:12 +01:00
										 |  |  |             info += ", #{Formatter.pluralize(command_count, "command")}" | 
					
						
							| 
									
										
										
										
											2015-09-21 14:16:11 +02:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2016-09-10 10:24:57 +01:00
										 |  |  |           info += ", no formulae/commands" if (formula_count + command_count).zero? | 
					
						
							| 
									
										
										
										
											2015-06-08 19:13:05 +08:00
										 |  |  |           info += "\n#{tap.path} (#{tap.path.abv})" | 
					
						
							| 
									
										
										
										
											2015-08-13 14:56:14 +08:00
										 |  |  |           info += "\nFrom: #{tap.remote.nil? ? "N/A" : tap.remote}" | 
					
						
							| 
									
										
										
										
											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 |