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
|
|
|
|
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 }
|
2009-10-26 18:16:42 +00:00
|
|
|
raise FormulaUnspecifiedError if @formulae.empty?
|
2009-10-24 18:09:43 +01:00
|
|
|
@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
|
|
|
|
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|
|
2011-09-01 16:14:45 -07:00
|
|
|
n = Formula.canonical_name(name)
|
|
|
|
rack = HOMEBREW_CELLAR + if n.include? "/"
|
|
|
|
# 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.
|
|
|
|
Pathname.new(n).stem
|
|
|
|
else
|
|
|
|
n
|
|
|
|
end
|
|
|
|
dirs = rack.children.select{ |pn| pn.directory? } rescue []
|
|
|
|
raise NoSuchKegError.new(name) if not rack.directory? or dirs.length == 0
|
2010-10-17 17:21:03 -07:00
|
|
|
raise MultipleVersionsInstalledError.new(name) if dirs.length > 1
|
2009-11-09 17:42:23 +00:00
|
|
|
Keg.new dirs.first
|
2009-08-10 16:27:24 +01:00
|
|
|
end
|
2009-10-26 18:16:42 +00:00
|
|
|
raise KegUnspecifiedError if @kegs.empty?
|
2009-10-24 18:09:43 +01:00
|
|
|
@kegs
|
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?
|
2009-10-01 14:44:23 +01:00
|
|
|
flag? '--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
|
|
|
|
|
2010-07-09 12:40:41 -07:00
|
|
|
def build_head?
|
|
|
|
flag? '--HEAD'
|
|
|
|
end
|
2010-11-24 09:40:37 +00:00
|
|
|
|
2011-11-20 20:09:33 -06:00
|
|
|
def build_devel?
|
|
|
|
include? '--devel'
|
|
|
|
end
|
|
|
|
|
2011-04-21 09:36:40 -07:00
|
|
|
def build_universal?
|
|
|
|
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?
|
|
|
|
MacOS.bottles_supported? and include? '--build-bottle'
|
|
|
|
end
|
|
|
|
|
2010-11-24 09:40:37 +00:00
|
|
|
def build_from_source?
|
2011-12-31 19:09:49 +00:00
|
|
|
flag? '--build-from-source' or ENV['HOMEBREW_BUILD_FROM_SOURCE'] \
|
|
|
|
or not MacOS.bottles_supported? or not options_only.empty?
|
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
|
|
|
|
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
|
|
|
|
|
|
|
yield
|
|
|
|
|
|
|
|
replace old_args
|
|
|
|
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
|