| 
									
										
										
										
											2020-10-10 14:16:11 +02:00
										 |  |  | # typed: false | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-02 09:05:49 +01:00
										 |  |  | require "json" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  | module Cask | 
					
						
							| 
									
										
										
										
											2018-09-04 08:45:48 +01:00
										 |  |  |   class Cmd | 
					
						
							| 
									
										
										
										
											2021-01-25 09:18:10 +00:00
										 |  |  |     # Cask implementation of the `brew info` command. | 
					
						
							| 
									
										
										
										
											2020-08-19 10:34:07 +02:00
										 |  |  |     # | 
					
						
							|  |  |  |     # @api private | 
					
						
							| 
									
										
										
										
											2017-05-20 19:08:03 +02:00
										 |  |  |     class Info < AbstractCommand | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |       extend T::Sig | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-01 02:30:46 +02:00
										 |  |  |       def self.parser | 
					
						
							|  |  |  |         super do | 
					
						
							| 
									
										
										
										
											2020-09-28 13:10:06 +09:00
										 |  |  |           flag   "--json=", | 
					
						
							|  |  |  |                  description: "Output information in JSON format." | 
					
						
							|  |  |  |           switch "--github", | 
					
						
							|  |  |  |                  description: "Open the GitHub source page for <Cask> in a browser. " | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def github_info(cask) | 
					
						
							|  |  |  |         sourcefile_path = cask.sourcefile_path | 
					
						
							|  |  |  |         dir = cask.tap.path | 
					
						
							|  |  |  |         path = sourcefile_path.relative_path_from(dir) | 
					
						
							|  |  |  |         remote = cask.tap.remote | 
					
						
							|  |  |  |         github_remote_path(remote, path) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def github_remote_path(remote, path) | 
					
						
							|  |  |  |         if remote =~ %r{^(?:https?://|git(?:@|://))github\.com[:/](.+)/(.+?)(?:\.git)?$} | 
					
						
							|  |  |  |           "https://github.com/#{Regexp.last_match(1)}/#{Regexp.last_match(2)}/blob/HEAD/#{path}" | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           "#{remote}/#{path}" | 
					
						
							| 
									
										
										
										
											2020-08-01 02:30:46 +02:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-05-20 18:31:07 +02:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |       sig { void } | 
					
						
							| 
									
										
										
										
											2017-05-20 18:31:07 +02:00
										 |  |  |       def run | 
					
						
							| 
									
										
										
										
											2020-08-01 02:30:46 +02:00
										 |  |  |         if args.json == "v1" | 
					
						
							| 
									
										
										
										
											2021-04-09 14:06:21 +01:00
										 |  |  |           puts JSON.pretty_generate(args.named.to_casks.map(&:to_h)) | 
					
						
							| 
									
										
										
										
											2020-09-28 13:10:06 +09:00
										 |  |  |         elsif args.github? | 
					
						
							|  |  |  |           raise CaskUnspecifiedError if args.no_named? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-08 20:00:45 -04:00
										 |  |  |           args.named.to_casks.map do |cask| | 
					
						
							| 
									
										
										
										
											2020-09-28 13:10:06 +09:00
										 |  |  |             exec_browser(github_info(cask)) | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2018-07-02 09:05:49 +01:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2020-10-08 20:00:45 -04:00
										 |  |  |           args.named.to_casks.each_with_index do |cask, i| | 
					
						
							| 
									
										
										
										
											2019-05-13 18:59:45 +01:00
										 |  |  |             puts unless i.zero? | 
					
						
							| 
									
										
										
										
											2018-07-02 09:05:49 +01:00
										 |  |  |             odebug "Getting info for Cask #{cask}" | 
					
						
							|  |  |  |             self.class.info(cask) | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 03:33:57 -05:00
										 |  |  |       def self.get_info(cask) | 
					
						
							| 
									
										
										
										
											2020-08-18 00:23:23 +01:00
										 |  |  |         require "cask/installer" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-19 17:12:32 +01:00
										 |  |  |         output = +"#{title_info(cask)}\n" | 
					
						
							|  |  |  |         output << "#{Formatter.url(cask.homepage)}\n" if cask.homepage | 
					
						
							| 
									
										
										
										
											2019-03-04 19:38:31 -05:00
										 |  |  |         output << installation_info(cask) | 
					
						
							|  |  |  |         repo = repo_info(cask) | 
					
						
							| 
									
										
										
										
											2020-08-19 17:12:32 +01:00
										 |  |  |         output << "#{repo}\n" if repo | 
					
						
							| 
									
										
										
										
											2019-03-04 19:38:31 -05:00
										 |  |  |         output << name_info(cask) | 
					
						
							| 
									
										
										
										
											2020-08-13 22:14:52 +01:00
										 |  |  |         output << desc_info(cask) | 
					
						
							| 
									
										
										
										
											2019-03-04 19:38:31 -05:00
										 |  |  |         language = language_info(cask) | 
					
						
							| 
									
										
										
										
											2019-03-16 12:59:15 -04:00
										 |  |  |         output << language if language | 
					
						
							| 
									
										
										
										
											2020-08-19 17:12:32 +01:00
										 |  |  |         output << "#{artifact_info(cask)}\n" | 
					
						
							| 
									
										
										
										
											2019-03-11 21:20:02 -04:00
										 |  |  |         caveats = Installer.caveats(cask) | 
					
						
							| 
									
										
										
										
											2019-03-16 12:59:15 -04:00
										 |  |  |         output << caveats if caveats | 
					
						
							| 
									
										
										
										
											2019-03-04 19:38:31 -05:00
										 |  |  |         output | 
					
						
							| 
									
										
										
										
											2019-02-18 03:33:57 -05:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |       def self.info(cask) | 
					
						
							| 
									
										
										
										
											2019-02-18 03:33:57 -05:00
										 |  |  |         puts get_info(cask) | 
					
						
							| 
									
										
										
										
											2020-07-24 23:16:30 +02:00
										 |  |  |         ::Utils::Analytics.cask_output(cask, args: Homebrew::CLI::Args.new) | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-15 16:16:55 +10:00
										 |  |  |       def self.title_info(cask) | 
					
						
							|  |  |  |         title = "#{cask.token}: #{cask.version}" | 
					
						
							|  |  |  |         title += " (auto_updates)" if cask.auto_updates | 
					
						
							| 
									
										
										
										
											2019-02-18 03:33:57 -05:00
										 |  |  |         title | 
					
						
							| 
									
										
										
										
											2018-06-15 16:16:55 +10:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |       def self.formatted_url(url) | 
					
						
							| 
									
										
										
										
											2016-08-26 16:04:47 +02:00
										 |  |  |         "#{Tty.underline}#{url}#{Tty.reset}" | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |       def self.installation_info(cask) | 
					
						
							| 
									
										
										
										
											2019-07-16 21:10:21 +01:00
										 |  |  |         return "Not installed\n" unless cask.installed? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-18 17:33:02 +09:00
										 |  |  |         install_info = +"" | 
					
						
							| 
									
										
										
										
											2019-07-16 21:10:21 +01:00
										 |  |  |         cask.versions.each do |version| | 
					
						
							|  |  |  |           versioned_staged_path = cask.caskroom_path.join(version) | 
					
						
							|  |  |  |           path_details = if versioned_staged_path.exist? | 
					
						
							|  |  |  |             versioned_staged_path.abv | 
					
						
							|  |  |  |           else | 
					
						
							|  |  |  |             Formatter.error("does not exist") | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2019-07-16 21:10:21 +01:00
										 |  |  |           install_info << "#{versioned_staged_path} (#{path_details})\n" | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2019-07-16 21:10:21 +01:00
										 |  |  |         install_info.freeze | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |       def self.name_info(cask) | 
					
						
							| 
									
										
										
										
											2019-02-18 03:33:57 -05:00
										 |  |  |         <<~EOS | 
					
						
							|  |  |  |           #{ohai_title((cask.name.size > 1) ? "Names" : "Name")} | 
					
						
							|  |  |  |           #{cask.name.empty? ? Formatter.error("None") : cask.name.join("\n")} | 
					
						
							|  |  |  |         EOS | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 20:16:24 +01:00
										 |  |  |       def self.desc_info(cask) | 
					
						
							|  |  |  |         <<~EOS | 
					
						
							|  |  |  |           #{ohai_title("Description")} | 
					
						
							| 
									
										
										
										
											2020-08-13 22:14:52 +01:00
										 |  |  |           #{cask.desc.nil? ? Formatter.error("None") : cask.desc} | 
					
						
							| 
									
										
										
										
											2020-08-13 20:16:24 +01:00
										 |  |  |         EOS | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-27 00:17:47 -07:00
										 |  |  |       def self.language_info(cask) | 
					
						
							|  |  |  |         return if cask.languages.empty? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 03:33:57 -05:00
										 |  |  |         <<~EOS | 
					
						
							|  |  |  |           #{ohai_title("Languages")} | 
					
						
							|  |  |  |           #{cask.languages.join(", ")} | 
					
						
							|  |  |  |         EOS | 
					
						
							| 
									
										
										
										
											2017-09-27 00:17:47 -07:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-16 19:15:31 +01:00
										 |  |  |       def self.repo_info(cask) | 
					
						
							| 
									
										
										
										
											2018-04-14 10:35:21 +02:00
										 |  |  |         return if cask.tap.nil? | 
					
						
							| 
									
										
										
										
											2017-06-03 00:05:13 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-14 10:35:21 +02:00
										 |  |  |         url = if cask.tap.custom_remote? && !cask.tap.remote.nil? | 
					
						
							|  |  |  |           cask.tap.remote | 
					
						
							| 
									
										
										
										
											2017-06-03 00:05:13 +02:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2020-06-25 11:20:57 +01:00
										 |  |  |           "#{cask.tap.default_remote}/blob/HEAD/Casks/#{cask.token}.rb" | 
					
						
							| 
									
										
										
										
											2016-10-23 17:04:03 +02:00
										 |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-11 21:20:02 -04:00
										 |  |  |         "From: #{Formatter.url(url)}" | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |       def self.artifact_info(cask) | 
					
						
							| 
									
										
										
										
											2019-04-20 14:07:29 +09:00
										 |  |  |         artifact_output = ohai_title("Artifacts").dup | 
					
						
							| 
									
										
										
										
											2017-10-04 17:08:35 +02:00
										 |  |  |         cask.artifacts.each do |artifact| | 
					
						
							|  |  |  |           next unless artifact.respond_to?(:install_phase) | 
					
						
							|  |  |  |           next unless DSL::ORDINARY_ARTIFACT_CLASSES.include?(artifact.class) | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-04 19:38:31 -05:00
										 |  |  |           artifact_output << "\n" << artifact.to_s | 
					
						
							| 
									
										
										
										
											2017-10-04 17:08:35 +02:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2019-04-20 14:07:29 +09:00
										 |  |  |         artifact_output.freeze | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |