2009-08-10 16:27:24 +01:00
|
|
|
module HomebrewArgvExtension
|
|
|
|
def named
|
2009-10-26 18:20:18 +00:00
|
|
|
@named ||= reject{|arg| arg[0..0] == '-'}
|
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
|
2009-08-10 16:27:24 +01:00
|
|
|
select {|arg| arg[0..0] == '-'}
|
|
|
|
end
|
2010-03-09 02:09:46 +00:00
|
|
|
|
2012-08-25 11:24:13 -07:00
|
|
|
def used_options f
|
|
|
|
f.build.as_flags & options_only
|
|
|
|
end
|
|
|
|
|
|
|
|
def unused_options f
|
|
|
|
f.build.as_flags - options_only
|
|
|
|
end
|
|
|
|
|
2009-08-10 16:27:24 +01:00
|
|
|
def formulae
|
|
|
|
require 'formula'
|
2010-11-05 13:44:24 +00:00
|
|
|
@formulae ||= downcased_unique_named.map{ |name| Formula.factory name }
|
2012-01-29 17:54:19 -08:00
|
|
|
return @formulae
|
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
|
2012-03-19 14:11:25 +00:00
|
|
|
rack = nil
|
2009-08-10 16:27:24 +01:00
|
|
|
require 'keg'
|
2010-09-22 12:32:16 -07:00
|
|
|
require 'formula'
|
2009-10-24 18:09:43 +01:00
|
|
|
@kegs ||= downcased_unique_named.collect do |name|
|
2012-03-06 13:43:41 +00:00
|
|
|
canonical_name = Formula.canonical_name(name)
|
|
|
|
rack = HOMEBREW_CELLAR + if canonical_name.include? "/"
|
2011-09-01 16:14:45 -07:00
|
|
|
# canonical_name returns a path if it was a formula installed via a
|
|
|
|
# URL. And we only want the name. FIXME that function is insane.
|
2012-03-06 13:43:41 +00:00
|
|
|
Pathname.new(canonical_name).stem
|
2011-09-01 16:14:45 -07:00
|
|
|
else
|
2012-03-06 13:43:41 +00:00
|
|
|
canonical_name
|
2011-09-01 16:14:45 -07:00
|
|
|
end
|
|
|
|
dirs = rack.children.select{ |pn| pn.directory? } rescue []
|
|
|
|
raise NoSuchKegError.new(name) if not rack.directory? or dirs.length == 0
|
2012-03-06 13:43:41 +00:00
|
|
|
|
|
|
|
linked_keg_ref = HOMEBREW_REPOSITORY/"Library/LinkedKegs"/name
|
|
|
|
|
|
|
|
if not linked_keg_ref.symlink?
|
2012-03-07 11:10:16 +00:00
|
|
|
if dirs.length == 1
|
|
|
|
Keg.new(dirs.first)
|
|
|
|
else
|
|
|
|
prefix = Formula.factory(canonical_name).prefix
|
|
|
|
if prefix.directory?
|
|
|
|
Keg.new(prefix)
|
|
|
|
else
|
|
|
|
raise MultipleVersionsInstalledError.new(name)
|
|
|
|
end
|
|
|
|
end
|
2012-03-06 13:43:41 +00:00
|
|
|
else
|
|
|
|
Keg.new(linked_keg_ref.realpath)
|
|
|
|
end
|
2009-08-10 16:27:24 +01:00
|
|
|
end
|
2012-03-19 14:11:25 +00:00
|
|
|
rescue FormulaUnavailableError
|
|
|
|
if rack
|
|
|
|
raise <<-EOS.undent
|
|
|
|
Multiple kegs installed to #{rack}
|
2012-03-19 14:19:56 +00:00
|
|
|
However we don't know which one you refer to.
|
|
|
|
Please delete (with rm -rf!) all but one and then try again.
|
|
|
|
Sorry, we know this is lame.
|
2012-03-19 14:11:25 +00:00
|
|
|
EOS
|
|
|
|
else
|
|
|
|
raise
|
|
|
|
end
|
2009-08-10 16:27:24 +01:00
|
|
|
end
|
2009-09-04 15:22:25 -07:00
|
|
|
|
2009-08-10 16:27:24 +01:00
|
|
|
# self documenting perhaps?
|
|
|
|
def include? arg
|
|
|
|
@n=index arg
|
|
|
|
end
|
|
|
|
def next
|
2009-10-26 18:20:47 +00:00
|
|
|
at @n+1 or raise UsageError
|
2009-08-10 16:27:24 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def force?
|
|
|
|
flag? '--force'
|
|
|
|
end
|
|
|
|
def verbose?
|
2012-08-21 11:34:35 -04:00
|
|
|
flag? '--verbose' or ENV['VERBOSE'] or ENV['HOMEBREW_VERBOSE']
|
2009-08-10 16:27:24 +01:00
|
|
|
end
|
|
|
|
def debug?
|
|
|
|
flag? '--debug' or ENV['HOMEBREW_DEBUG']
|
|
|
|
end
|
2009-09-03 17:10:35 +02:00
|
|
|
def quieter?
|
|
|
|
flag? '--quieter'
|
|
|
|
end
|
2009-09-10 14:29:41 +01:00
|
|
|
def interactive?
|
|
|
|
flag? '--interactive'
|
|
|
|
end
|
2011-04-21 09:36:40 -07:00
|
|
|
def one?
|
|
|
|
flag? '--1'
|
|
|
|
end
|
2012-06-17 18:44:35 -05:00
|
|
|
def dry_run?
|
|
|
|
include?('--dry-run') || switch?('n')
|
|
|
|
end
|
2011-04-21 09:36:40 -07:00
|
|
|
|
2012-12-31 17:51:57 +00:00
|
|
|
def homebrew_developer?
|
|
|
|
include? '--homebrew-developer' or ENV['HOMEBREW_DEVELOPER']
|
|
|
|
end
|
|
|
|
|
2012-08-18 18:12:12 -05:00
|
|
|
def ignore_deps?
|
|
|
|
include? '--ignore-dependencies'
|
|
|
|
end
|
|
|
|
|
2012-08-15 21:53:16 -05:00
|
|
|
def json
|
|
|
|
json_rev = find {|o| o =~ /--json=.+/}
|
|
|
|
json_rev.split("=").last if json_rev
|
|
|
|
end
|
|
|
|
|
2010-07-09 12:40:41 -07:00
|
|
|
def build_head?
|
2012-04-10 21:47:17 -05:00
|
|
|
include? '--HEAD'
|
2010-07-09 12:40:41 -07:00
|
|
|
end
|
2010-11-24 09:40:37 +00:00
|
|
|
|
2011-11-20 20:09:33 -06:00
|
|
|
def build_devel?
|
|
|
|
include? '--devel'
|
|
|
|
end
|
|
|
|
|
2012-06-10 14:49:56 -07:00
|
|
|
def build_stable?
|
|
|
|
not (build_head? or build_devel?)
|
|
|
|
end
|
|
|
|
|
2011-04-21 09:36:40 -07:00
|
|
|
def build_universal?
|
2012-03-10 19:21:14 +13:00
|
|
|
include? '--universal'
|
2010-09-25 12:49:09 +01:00
|
|
|
end
|
2009-08-10 16:27:24 +01:00
|
|
|
|
2012-01-01 13:48:30 -08:00
|
|
|
# Request a 32-bit only build.
|
|
|
|
# This is needed for some use-cases though we prefer to build Universal
|
|
|
|
# when a 32-bit version is needed.
|
|
|
|
def build_32_bit?
|
|
|
|
include? '--32-bit'
|
|
|
|
end
|
|
|
|
|
2011-12-31 19:09:49 +00:00
|
|
|
def build_bottle?
|
2012-12-04 12:06:02 +00:00
|
|
|
include? '--build-bottle' and MacOS.bottles_supported?(true)
|
2011-12-31 19:09:49 +00:00
|
|
|
end
|
|
|
|
|
2010-11-24 09:40:37 +00:00
|
|
|
def build_from_source?
|
2012-09-18 17:53:51 +01:00
|
|
|
include? '--build-from-source' or ENV['HOMEBREW_BUILD_FROM_SOURCE'] \
|
2012-09-30 20:38:38 +01:00
|
|
|
or build_head? or build_devel? or build_universal? or build_bottle?
|
2010-11-24 09:40:37 +00:00
|
|
|
end
|
|
|
|
|
2009-08-10 16:27:24 +01:00
|
|
|
def flag? flag
|
2010-07-13 07:31:43 -07:00
|
|
|
options_only.each do |arg|
|
2009-08-10 16:27:24 +01:00
|
|
|
return true if arg == flag
|
|
|
|
next if arg[1..1] == '-'
|
|
|
|
return true if arg.include? flag[2..2]
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
2009-09-04 15:22:25 -07:00
|
|
|
|
2012-03-06 20:11:35 +00:00
|
|
|
# eg. `foo -ns -i --bar` has three switches, n, s and i
|
|
|
|
def switch? switch_character
|
|
|
|
return false if switch_character.length > 1
|
|
|
|
options_only.each do |arg|
|
|
|
|
next if arg[1..1] == '-'
|
|
|
|
return true if arg.include? switch_character
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2011-03-13 12:54:30 +00:00
|
|
|
def usage
|
|
|
|
require 'cmd/help'
|
|
|
|
Homebrew.help_s
|
2009-08-10 16:27:24 +01:00
|
|
|
end
|
2009-09-04 15:22:25 -07:00
|
|
|
|
2011-11-26 21:03:46 -08:00
|
|
|
def filter_for_dependencies
|
|
|
|
# Clears some flags that affect installation, yields to a block, then
|
|
|
|
# restores to original state.
|
|
|
|
old_args = clone
|
|
|
|
|
2011-11-27 14:20:37 -08:00
|
|
|
flags_to_clear = %w[
|
2011-11-26 21:03:46 -08:00
|
|
|
--debug -d
|
2011-11-27 14:17:35 -08:00
|
|
|
--devel
|
2011-11-26 21:03:46 -08:00
|
|
|
--fresh
|
|
|
|
--interactive -i
|
|
|
|
--HEAD
|
2011-11-27 14:20:37 -08:00
|
|
|
]
|
2011-11-27 14:44:39 -08:00
|
|
|
flags_to_clear.concat %w[--verbose -v] if quieter?
|
2011-11-27 14:20:37 -08:00
|
|
|
flags_to_clear.each {|flag| delete flag}
|
2011-11-26 21:03:46 -08:00
|
|
|
|
2013-01-10 15:57:21 -06:00
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
replace(old_args)
|
2011-11-26 21:03:46 -08:00
|
|
|
end
|
|
|
|
|
2010-08-07 22:15:29 -07:00
|
|
|
private
|
|
|
|
|
|
|
|
def downcased_unique_named
|
2010-09-22 07:54:53 -07:00
|
|
|
# Only lowercase names, not paths or URLs
|
|
|
|
@downcased_unique_named ||= named.map do |arg|
|
|
|
|
arg.include?("/") ? arg : arg.downcase
|
|
|
|
end.uniq
|
2010-08-07 22:15:29 -07:00
|
|
|
end
|
2009-08-10 16:27:24 +01:00
|
|
|
end
|