| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-10 16:27:24 +01:00
										 |  |  | module HomebrewArgvExtension | 
					
						
							| 
									
										
										
										
											2014-08-29 19:38:32 -05:00
										 |  |  |   def flags_only | 
					
						
							|  |  |  |     select { |arg| arg.start_with?("--") } | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-10 16:27:24 +01:00
										 |  |  |   def formulae | 
					
						
							| 
									
										
										
										
											2014-06-19 21:35:47 -05:00
										 |  |  |     require "formula" | 
					
						
							| 
									
										
										
										
											2019-02-18 16:56:43 +00:00
										 |  |  |     (downcased_unique_named - casks).map do |name| | 
					
						
							| 
									
										
										
										
											2015-08-09 22:43:01 +08:00
										 |  |  |       if name.include?("/") || File.exist?(name) | 
					
						
							|  |  |  |         Formulary.factory(name, spec) | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         Formulary.find_with_priority(name, spec) | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-12-31 17:03:29 +00:00
										 |  |  |     end.uniq(&:name) | 
					
						
							| 
									
										
										
										
											2014-11-28 15:02:42 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def casks | 
					
						
							| 
									
										
										
										
											2019-02-18 16:56:43 +00:00
										 |  |  |     # TODO: use @instance variable to ||= cache when moving to CLI::Parser | 
					
						
							|  |  |  |     downcased_unique_named.grep HOMEBREW_CASK_TAP_CASK_REGEX | 
					
						
							| 
									
										
										
										
											2009-08-10 16:27:24 +01:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2010-03-09 02:09:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-11 05:08:09 +02:00
										 |  |  |   def value(name) | 
					
						
							|  |  |  |     arg_prefix = "--#{name}=" | 
					
						
							|  |  |  |     flag_with_value = find { |arg| arg.start_with?(arg_prefix) } | 
					
						
							| 
									
										
										
										
											2018-09-15 00:04:01 +02:00
										 |  |  |     flag_with_value&.delete_prefix(arg_prefix) | 
					
						
							| 
									
										
										
										
											2013-07-07 09:14:10 -07:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-10 16:27:24 +01:00
										 |  |  |   def debug? | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     flag?("--debug") || !ENV["HOMEBREW_DEBUG"].nil? | 
					
						
							| 
									
										
										
										
											2009-08-10 16:27:24 +01:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-10 14:29:41 +01:00
										 |  |  |   def interactive? | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     flag? "--interactive" | 
					
						
							| 
									
										
										
										
											2009-09-10 14:29:41 +01:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-10 22:53:56 -04:00
										 |  |  |   def keep_tmp? | 
					
						
							|  |  |  |     include? "--keep-tmp" | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-03 21:33:20 -06:00
										 |  |  |   def git? | 
					
						
							|  |  |  |     flag? "--git" | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-31 17:51:57 +00:00
										 |  |  |   def homebrew_developer? | 
					
						
							| 
									
										
										
										
											2016-01-21 16:51:45 +01:00
										 |  |  |     !ENV["HOMEBREW_DEVELOPER"].nil? | 
					
						
							| 
									
										
										
										
											2012-12-31 17:51:57 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-05 19:48:38 -07:00
										 |  |  |   def skip_or_later_bottles? | 
					
						
							|  |  |  |     homebrew_developer? && !ENV["HOMEBREW_SKIP_OR_LATER_BOTTLES"].nil? | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-09 16:28:13 +00:00
										 |  |  |   def no_sandbox? | 
					
						
							|  |  |  |     include?("--no-sandbox") || !ENV["HOMEBREW_NO_SANDBOX"].nil? | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-18 18:12:12 -05:00
										 |  |  |   def ignore_deps? | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     include? "--ignore-dependencies" | 
					
						
							| 
									
										
										
										
											2012-08-18 18:12:12 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-10 14:49:56 -07:00
										 |  |  |   def build_stable? | 
					
						
							| 
									
										
										
										
											2019-04-17 17:34:57 +09:00
										 |  |  |     !(include?("--HEAD") || include?("--devel")) | 
					
						
							| 
									
										
										
										
											2012-06-10 14:49:56 -07:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-21 09:36:40 -07:00
										 |  |  |   def build_universal? | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     include? "--universal" | 
					
						
							| 
									
										
										
										
											2010-09-25 12:49:09 +01:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2009-08-10 16:27:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-31 19:09:49 +00:00
										 |  |  |   def build_bottle? | 
					
						
							| 
									
										
										
										
											2019-12-30 10:34:43 +00:00
										 |  |  |     include?("--build-bottle") | 
					
						
							| 
									
										
										
										
											2011-12-31 19:09:49 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-25 14:14:53 -07:00
										 |  |  |   def bottle_arch | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     arch = value "bottle-arch" | 
					
						
							| 
									
										
										
										
											2017-09-24 19:24:46 +01:00
										 |  |  |     arch&.to_sym | 
					
						
							| 
									
										
										
										
											2013-08-25 14:14:53 -07:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-24 09:40:37 +00:00
										 |  |  |   def build_from_source? | 
					
						
							| 
									
										
										
										
											2016-05-06 12:02:13 -07:00
										 |  |  |     switch?("s") || include?("--build-from-source") | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   # Whether a given formula should be built from source during the current | 
					
						
							|  |  |  |   # installation run. | 
					
						
							|  |  |  |   def build_formula_from_source?(f) | 
					
						
							| 
									
										
										
										
											2019-01-23 21:57:37 +00:00
										 |  |  |     return false if !build_from_source? && !build_bottle? | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-06 12:02:13 -07:00
										 |  |  |     formulae.any? { |argv_f| argv_f.full_name == f.full_name } | 
					
						
							| 
									
										
										
										
											2010-11-24 09:40:37 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-01 12:59:01 +01:00
										 |  |  |   def force_bottle? | 
					
						
							| 
									
										
										
										
											2018-07-24 09:20:50 +01:00
										 |  |  |     include?("--force-bottle") | 
					
						
							| 
									
										
										
										
											2013-09-01 12:59:01 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-23 22:25:35 -07:00
										 |  |  |   def cc | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     value "cc" | 
					
						
							| 
									
										
										
										
											2013-08-23 22:25:35 -07:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-13 10:10:59 -05:00
										 |  |  |   def env | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     value "env" | 
					
						
							| 
									
										
										
										
											2014-03-13 10:10:59 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-12 14:57:54 -04:00
										 |  |  |   # If the user passes any flags that trigger building over installing from | 
					
						
							|  |  |  |   # a bottle, they are collected here and returned as an Array for checking. | 
					
						
							| 
									
										
										
										
											2015-06-29 14:09:57 -04:00
										 |  |  |   def collect_build_flags | 
					
						
							|  |  |  |     build_flags = [] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-02 08:16:55 +01:00
										 |  |  |     build_flags << "--HEAD" if include?("--HEAD") | 
					
						
							| 
									
										
										
										
											2015-08-22 13:15:33 +08:00
										 |  |  |     build_flags << "--universal" if build_universal? | 
					
						
							|  |  |  |     build_flags << "--build-bottle" if build_bottle? | 
					
						
							|  |  |  |     build_flags << "--build-from-source" if build_from_source? | 
					
						
							| 
									
										
										
										
											2015-06-29 14:09:57 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     build_flags | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-28 21:35:52 -05:00
										 |  |  |   private | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-02 14:07:07 +00:00
										 |  |  |   def options_only | 
					
						
							|  |  |  |     select { |arg| arg.start_with?("-") } | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def flag?(flag) | 
					
						
							|  |  |  |     options_only.include?(flag) || switch?(flag[2, 1]) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 17:34:57 +09:00
										 |  |  |   # e.g. `foo -ns -i --bar` has three switches: `n`, `s` and `i` | 
					
						
							|  |  |  |   def switch?(char) | 
					
						
							|  |  |  |     return false if char.length > 1
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     options_only.any? { |arg| arg.scan("-").size == 1 && arg.include?(char) } | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   def spec(default = :stable) | 
					
						
							| 
									
										
										
										
											2014-06-19 21:35:47 -05:00
										 |  |  |     if include?("--HEAD") | 
					
						
							|  |  |  |       :head | 
					
						
							|  |  |  |     elsif include?("--devel") | 
					
						
							|  |  |  |       :devel | 
					
						
							|  |  |  |     else | 
					
						
							| 
									
										
										
										
											2015-07-30 16:31:47 +08:00
										 |  |  |       default | 
					
						
							| 
									
										
										
										
											2014-06-19 21:35:47 -05:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-04 17:27:52 +00:00
										 |  |  |   def named | 
					
						
							|  |  |  |     self - options_only | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-07 22:15:29 -07:00
										 |  |  |   def downcased_unique_named | 
					
						
							| 
									
										
										
										
											2015-08-05 09:51:37 -07:00
										 |  |  |     # Only lowercase names, not paths, bottle filenames or URLs | 
					
						
							| 
									
										
										
										
											2019-02-18 16:56:43 +00:00
										 |  |  |     named.map do |arg| | 
					
						
							| 
									
										
										
										
											2016-07-16 20:58:56 +08:00
										 |  |  |       if arg.include?("/") || arg.end_with?(".tar.gz") || File.exist?(arg) | 
					
						
							| 
									
										
										
										
											2015-08-05 09:51:37 -07:00
										 |  |  |         arg | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         arg.downcase | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2010-09-22 07:54:53 -07:00
										 |  |  |     end.uniq | 
					
						
							| 
									
										
										
										
											2010-08-07 22:15:29 -07:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2009-08-10 16:27:24 +01:00
										 |  |  | end |