| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | # Caveats DSL. Each method should handle output, following the | 
					
						
							|  |  |  | # convention of at least one trailing blank line so that the user | 
					
						
							|  |  |  | # can distinguish separate caveats. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # ( The return value of the last method in the block is also sent | 
					
						
							|  |  |  | #   to the output by the caller, but that feature is only for the | 
					
						
							|  |  |  | #   convenience of Cask authors. ) | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  | module Cask | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |   class DSL | 
					
						
							|  |  |  |     class Caveats < Base | 
					
						
							| 
									
										
										
										
											2017-11-24 17:44:01 +01:00
										 |  |  |       def initialize(*args) | 
					
						
							|  |  |  |         super(*args) | 
					
						
							|  |  |  |         @built_in_caveats = {} | 
					
						
							|  |  |  |         @custom_caveats = [] | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def self.caveat(name, &block) | 
					
						
							|  |  |  |         define_method(name) do |*args| | 
					
						
							|  |  |  |           key = [name, *args] | 
					
						
							| 
									
										
										
										
											2017-11-28 21:59:12 +01:00
										 |  |  |           text = instance_exec(*args, &block) | 
					
						
							|  |  |  |           @built_in_caveats[key] = text if text | 
					
						
							| 
									
										
										
										
											2017-11-24 17:44:01 +01:00
										 |  |  |           :built_in_caveat | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       private_class_method :caveat | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def to_s | 
					
						
							|  |  |  |         (@custom_caveats + @built_in_caveats.values).join("\n") | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       # Override `puts` to collect caveats. | 
					
						
							|  |  |  |       def puts(*args) | 
					
						
							|  |  |  |         @custom_caveats += args | 
					
						
							|  |  |  |         :built_in_caveat | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def eval_caveats(&block) | 
					
						
							|  |  |  |         result = instance_eval(&block) | 
					
						
							|  |  |  |         return unless result | 
					
						
							|  |  |  |         return if result == :built_in_caveat | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-24 17:44:01 +01:00
										 |  |  |         @custom_caveats << result.to_s.sub(/\s*\Z/, "\n") | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       caveat :kext do | 
					
						
							| 
									
										
										
										
											2017-11-28 21:59:12 +01:00
										 |  |  |         next if MacOS.version < :high_sierra | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-24 17:44:01 +01:00
										 |  |  |         <<~EOS | 
					
						
							| 
									
										
										
										
											2020-03-23 16:13:50 +00:00
										 |  |  |           #{@cask} requires a kernel extension to work. | 
					
						
							|  |  |  |           If the installation fails, retry after you enable it in: | 
					
						
							| 
									
										
										
										
											2017-11-24 17:44:01 +01:00
										 |  |  |             System Preferences → Security & Privacy → General | 
					
						
							| 
									
										
										
										
											2020-03-23 16:13:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |           For more information, refer to vendor documentation or this Apple Technical Note: | 
					
						
							| 
									
										
										
										
											2017-11-24 17:44:01 +01:00
										 |  |  |             #{Formatter.url("https://developer.apple.com/library/content/technotes/tn2459/_index.html")} | 
					
						
							|  |  |  |         EOS | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-26 20:17:10 +01:00
										 |  |  |       caveat :unsigned_accessibility do |access = "Accessibility"| | 
					
						
							|  |  |  |         # access: the category in System Preferences -> Security & Privacy -> Privacy the app requires. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         <<~EOS | 
					
						
							|  |  |  |           #{@cask} is not signed and requires Accessibility access, | 
					
						
							|  |  |  |           so you will need to re-grant Accessibility access every time the app is updated. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           Enable or re-enable it in: | 
					
						
							|  |  |  |             System Preferences → Security & Privacy → Privacy -> #{access} | 
					
						
							|  |  |  |           To re-enable untick and retick #{@cask}.app. | 
					
						
							|  |  |  |         EOS | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-24 17:44:01 +01:00
										 |  |  |       caveat :path_environment_variable do |path| | 
					
						
							|  |  |  |         <<~EOS | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |           To use #{@cask}, you may need to add the #{path} directory | 
					
						
							| 
									
										
										
										
											2019-04-08 12:47:15 -04:00
										 |  |  |           to your PATH environment variable, e.g. (for bash shell): | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |             export PATH=#{path}:"$PATH" | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |         EOS | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-24 17:44:01 +01:00
										 |  |  |       caveat :zsh_path_helper do |path| | 
					
						
							|  |  |  |         <<~EOS | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |           To use #{@cask}, zsh users may need to add the following line to their | 
					
						
							|  |  |  |           ~/.zprofile.  (Among other effects, #{path} will be added to the
 | 
					
						
							|  |  |  |           PATH environment variable): | 
					
						
							|  |  |  |             eval `/usr/libexec/path_helper -s` | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |         EOS | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-24 17:44:01 +01:00
										 |  |  |       caveat :files_in_usr_local do | 
					
						
							|  |  |  |         next unless HOMEBREW_PREFIX.to_s.downcase.start_with?("/usr/local") | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-24 17:44:01 +01:00
										 |  |  |         <<~EOS | 
					
						
							|  |  |  |           Cask #{@cask} installs files under /usr/local. The presence of such | 
					
						
							| 
									
										
										
										
											2019-04-05 12:24:10 -04:00
										 |  |  |           files can cause warnings when running `brew doctor`, which is considered | 
					
						
							| 
									
										
										
										
											2018-09-03 20:12:29 +01:00
										 |  |  |           to be a bug in Homebrew Cask. | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |         EOS | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-24 17:44:01 +01:00
										 |  |  |       caveat :depends_on_java do |java_version = :any| | 
					
						
							|  |  |  |         if java_version == :any | 
					
						
							|  |  |  |           <<~EOS | 
					
						
							| 
									
										
										
										
											2019-04-08 12:47:15 -04:00
										 |  |  |             #{@cask} requires Java. You can install the latest version with: | 
					
						
							| 
									
										
										
										
											2019-09-14 11:23:41 -04:00
										 |  |  |               brew cask install adoptopenjdk | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |           EOS | 
					
						
							| 
									
										
										
										
											2018-09-12 08:30:35 +10:00
										 |  |  |         elsif java_version.include?("11") || java_version.include?("+") | 
					
						
							| 
									
										
										
										
											2017-11-24 17:44:01 +01:00
										 |  |  |           <<~EOS | 
					
						
							| 
									
										
										
										
											2019-04-08 12:47:15 -04:00
										 |  |  |             #{@cask} requires Java #{java_version}. You can install the latest version with: | 
					
						
							| 
									
										
										
										
											2019-09-14 11:23:41 -04:00
										 |  |  |               brew cask install adoptopenjdk | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |           EOS | 
					
						
							|  |  |  |         else | 
					
						
							| 
									
										
										
										
											2017-11-24 17:44:01 +01:00
										 |  |  |           <<~EOS | 
					
						
							| 
									
										
										
										
											2019-04-08 12:47:15 -04:00
										 |  |  |             #{@cask} requires Java #{java_version}. You can install it with: | 
					
						
							| 
									
										
										
										
											2019-09-14 11:23:41 -04:00
										 |  |  |               brew cask install homebrew/cask-versions/adoptopenjdk#{java_version} | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |           EOS | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-24 17:44:01 +01:00
										 |  |  |       caveat :logout do | 
					
						
							|  |  |  |         <<~EOS | 
					
						
							|  |  |  |           You must log out and log back in for the installation of #{@cask} to take effect. | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |         EOS | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-24 17:44:01 +01:00
										 |  |  |       caveat :reboot do | 
					
						
							|  |  |  |         <<~EOS | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |           You must reboot for the installation of #{@cask} to take effect. | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |         EOS | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-24 17:44:01 +01:00
										 |  |  |       caveat :discontinued do | 
					
						
							|  |  |  |         <<~EOS | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |           #{@cask} has been officially discontinued upstream. | 
					
						
							|  |  |  |           It may stop working correctly (or at all) in recent versions of macOS. | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |         EOS | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 19:56:03 +10:00
										 |  |  |       caveat :license do |web_page| | 
					
						
							|  |  |  |         <<~EOS | 
					
						
							| 
									
										
										
										
											2019-04-08 12:47:15 -04:00
										 |  |  |           Installing #{@cask} means you have AGREED to the license at: | 
					
						
							| 
									
										
										
										
											2019-04-05 12:24:10 -04:00
										 |  |  |             #{Formatter.url(web_page.to_s)} | 
					
						
							| 
									
										
										
										
											2018-05-15 19:56:03 +10:00
										 |  |  |         EOS | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-24 17:44:01 +01:00
										 |  |  |       caveat :free_license do |web_page| | 
					
						
							|  |  |  |         <<~EOS | 
					
						
							| 
									
										
										
										
											2019-04-08 12:47:15 -04:00
										 |  |  |           The vendor offers a free license for #{@cask} at: | 
					
						
							| 
									
										
										
										
											2019-04-05 12:24:10 -04:00
										 |  |  |             #{Formatter.url(web_page.to_s)} | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |         EOS | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |   end | 
					
						
							|  |  |  | end |