2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2009-08-10 16:27:24 +01:00
|
|
|
module HomebrewArgvExtension
|
|
|
|
def named
|
2019-02-18 16:56:43 +00:00
|
|
|
# TODO: use @instance variable to ||= cache when moving to CLI::Parser
|
|
|
|
self - options_only
|
2009-08-10 16:27:24 +01:00
|
|
|
end
|
2010-03-09 02:09:46 +00:00
|
|
|
|
2010-07-13 07:31:43 -07:00
|
|
|
def options_only
|
2014-08-28 22:11:08 -05:00
|
|
|
select { |arg| arg.start_with?("-") }
|
2009-08-10 16:27:24 +01:00
|
|
|
end
|
2010-03-09 02:09:46 +00:00
|
|
|
|
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
|
|
|
# TODO: use @instance variable to ||= cache when moving to CLI::Parser
|
|
|
|
(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
|
|
|
|
|
2015-05-17 00:53:41 +08:00
|
|
|
def resolved_formulae
|
|
|
|
require "formula"
|
2019-02-18 16:56:43 +00:00
|
|
|
# TODO: use @instance variable to ||= cache when moving to CLI::Parser
|
|
|
|
(downcased_unique_named - casks).map do |name|
|
2018-09-11 17:44:18 +02:00
|
|
|
Formulary.resolve(name, spec: spec(nil))
|
2016-12-31 17:03:29 +00:00
|
|
|
end.uniq(&:name)
|
2015-05-17 00:53:41 +08:00
|
|
|
end
|
|
|
|
|
2014-11-28 15:02:42 +00:00
|
|
|
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
|
|
|
|
2009-08-10 16:27:24 +01:00
|
|
|
def kegs
|
2015-08-03 13:09:07 +01:00
|
|
|
require "keg"
|
|
|
|
require "formula"
|
2019-02-18 16:56:43 +00:00
|
|
|
# TODO: use @instance variable to ||= cache when moving to CLI::Parser
|
|
|
|
downcased_unique_named.map do |name|
|
2016-09-25 11:04:16 -04:00
|
|
|
raise UsageError if name.empty?
|
|
|
|
|
2016-07-16 21:05:28 +08:00
|
|
|
rack = Formulary.to_rack(name.downcase)
|
2015-08-09 14:56:01 +03:00
|
|
|
|
2014-03-15 12:55:14 -05:00
|
|
|
dirs = rack.directory? ? rack.subdirs : []
|
2014-04-05 22:03:34 -05:00
|
|
|
|
2016-09-11 17:53:00 +01:00
|
|
|
raise NoSuchKegError, rack.basename if dirs.empty?
|
2012-03-06 13:43:41 +00:00
|
|
|
|
2016-09-15 18:28:42 +01:00
|
|
|
linked_keg_ref = HOMEBREW_LINKED_KEGS/rack.basename
|
|
|
|
opt_prefix = HOMEBREW_PREFIX/"opt/#{rack.basename}"
|
2012-03-06 13:43:41 +00:00
|
|
|
|
2014-06-26 22:28:00 -05:00
|
|
|
begin
|
|
|
|
if opt_prefix.symlink? && opt_prefix.directory?
|
|
|
|
Keg.new(opt_prefix.resolved_path)
|
|
|
|
elsif linked_keg_ref.symlink? && linked_keg_ref.directory?
|
|
|
|
Keg.new(linked_keg_ref.resolved_path)
|
|
|
|
elsif dirs.length == 1
|
|
|
|
Keg.new(dirs.first)
|
|
|
|
else
|
2016-07-16 21:05:28 +08:00
|
|
|
f = if name.include?("/") || File.exist?(name)
|
|
|
|
Formulary.factory(name)
|
|
|
|
else
|
|
|
|
Formulary.from_rack(rack)
|
|
|
|
end
|
|
|
|
|
2016-09-23 22:02:23 +02:00
|
|
|
unless (prefix = f.installed_prefix).directory?
|
2016-09-11 17:53:00 +01:00
|
|
|
raise MultipleVersionsInstalledError, rack.basename
|
2016-07-16 21:05:28 +08:00
|
|
|
end
|
2016-09-23 22:02:23 +02:00
|
|
|
|
|
|
|
Keg.new(prefix)
|
2014-06-26 22:28:00 -05:00
|
|
|
end
|
|
|
|
rescue FormulaUnavailableError
|
2017-10-15 02:28:32 +02:00
|
|
|
raise <<~EOS
|
2014-06-26 22:28:00 -05:00
|
|
|
Multiple kegs installed to #{rack}
|
|
|
|
However we don't know which one you refer to.
|
|
|
|
Please delete (with rm -rf!) all but one and then try again.
|
|
|
|
EOS
|
2012-03-06 13:43:41 +00:00
|
|
|
end
|
2009-08-10 16:27:24 +01:00
|
|
|
end
|
|
|
|
end
|
2009-09-04 15:22:25 -07: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 force?
|
2015-08-03 13:09:07 +01:00
|
|
|
flag? "--force"
|
2009-08-10 16:27:24 +01:00
|
|
|
end
|
2015-08-03 13:09:07 +01:00
|
|
|
|
2009-08-10 16:27:24 +01:00
|
|
|
def verbose?
|
2015-08-03 13:09:07 +01:00
|
|
|
flag?("--verbose") || !ENV["VERBOSE"].nil? || !ENV["HOMEBREW_VERBOSE"].nil?
|
2009-08-10 16:27:24 +01:00
|
|
|
end
|
2015-08-03 13:09:07 +01:00
|
|
|
|
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-03 17:10:35 +02:00
|
|
|
def quieter?
|
2015-08-03 13:09:07 +01:00
|
|
|
flag? "--quieter"
|
2009-09-03 17:10:35 +02: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
|
|
|
|
|
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?
|
2015-08-03 13:09:07 +01:00
|
|
|
include?("--build-bottle") || !ENV["HOMEBREW_BUILD_BOTTLE"].nil?
|
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
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def flag?(flag)
|
2014-08-28 22:11:08 -05:00
|
|
|
options_only.include?(flag) || switch?(flag[2, 1])
|
2009-08-10 16:27:24 +01:00
|
|
|
end
|
2009-09-04 15:22:25 -07:00
|
|
|
|
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
|
|
|
|
|
2016-07-22 12:47:47 +03:00
|
|
|
def fetch_head?
|
|
|
|
include? "--fetch-HEAD"
|
|
|
|
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 = []
|
|
|
|
|
2015-08-22 13:15:33 +08:00
|
|
|
build_flags << "--HEAD" if build_head?
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
# TODO: use @instance variable to ||= cache when moving to CLI::Parser
|
|
|
|
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
|