2009-10-26 18:16:42 +00:00
|
|
|
class UsageError <RuntimeError; end
|
|
|
|
class FormulaUnspecifiedError <UsageError; end
|
|
|
|
class KegUnspecifiedError <UsageError; end
|
|
|
|
|
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-03-09 02:09:46 +00:00
|
|
|
@formulae ||= downcased_unique_named.map{ |name| Formula.factory(resolve_alias(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'
|
2009-10-24 18:09:43 +01:00
|
|
|
@kegs ||= downcased_unique_named.collect do |name|
|
2010-03-09 02:09:46 +00:00
|
|
|
d = HOMEBREW_CELLAR + resolve_alias(name)
|
2009-11-09 17:42:23 +00:00
|
|
|
dirs = d.children.select{ |pn| pn.directory? } rescue []
|
2010-03-09 02:09:46 +00:00
|
|
|
raise "No such keg: #{HOMEBREW_CELLAR}/#{name}" if not d.directory? or dirs.length == 0
|
2009-11-09 17:42:23 +00:00
|
|
|
raise "#{name} has multiple installed versions" if dirs.length > 1
|
|
|
|
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
|
2010-07-09 12:40:41 -07:00
|
|
|
def build_head?
|
|
|
|
flag? '--HEAD'
|
|
|
|
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
|
|
|
|
2010-02-27 17:26:27 +00:00
|
|
|
def usage; <<-EOS.undent
|
2010-09-04 12:48:37 +02:00
|
|
|
Usage: brew [-v|--version] [--prefix [formula]] [--cache [formula]]
|
|
|
|
[--cellar [formula]] [--config] [--env] [--repository]
|
|
|
|
[-h|--help] COMMAND [formula] ...
|
2009-08-10 16:27:24 +01:00
|
|
|
|
2010-02-27 17:26:27 +00:00
|
|
|
Principle Commands:
|
2010-08-11 21:15:59 -07:00
|
|
|
install formula ... [--ignore-dependencies] [--HEAD]
|
|
|
|
list [--unbrewed|--versions] [formula] ...
|
2010-02-27 17:26:27 +00:00
|
|
|
search [/regex/] [substring]
|
|
|
|
uninstall formula ...
|
|
|
|
update
|
2010-02-27 16:06:05 +00:00
|
|
|
|
2010-02-27 17:26:27 +00:00
|
|
|
Other Commands:
|
2010-08-11 21:15:59 -07:00
|
|
|
info formula [--github]
|
2010-09-08 05:27:09 -07:00
|
|
|
options formula
|
2010-08-11 21:15:59 -07:00
|
|
|
deps formula
|
|
|
|
uses formula [--installed]
|
2010-02-27 17:26:27 +00:00
|
|
|
home formula ...
|
2010-08-11 21:15:59 -07:00
|
|
|
cleanup [formula]
|
2010-02-27 17:26:27 +00:00
|
|
|
link formula ...
|
2010-08-11 21:15:59 -07:00
|
|
|
unlink formula ...
|
2010-02-27 17:26:27 +00:00
|
|
|
outdated
|
2010-09-08 05:27:09 -07:00
|
|
|
missing
|
2010-02-27 17:26:27 +00:00
|
|
|
prune
|
2010-08-11 21:15:59 -07:00
|
|
|
doctor
|
|
|
|
|
|
|
|
Informational:
|
|
|
|
--version
|
|
|
|
--config
|
|
|
|
--prefix [formula]
|
|
|
|
--cache [formula]
|
2009-09-04 15:22:25 -07:00
|
|
|
|
2010-02-27 17:26:27 +00:00
|
|
|
Commands useful when contributing:
|
|
|
|
create URL
|
|
|
|
edit [formula]
|
2010-08-11 21:15:59 -07:00
|
|
|
audit [formula]
|
2010-02-27 17:26:27 +00:00
|
|
|
log formula
|
2010-08-11 21:15:59 -07:00
|
|
|
install formula [-vd|-i]
|
2009-09-24 19:19:57 +01:00
|
|
|
|
2010-07-09 12:16:06 -07:00
|
|
|
For more information:
|
|
|
|
man brew
|
|
|
|
|
2010-02-27 17:26:27 +00:00
|
|
|
To visit the Homebrew homepage type:
|
|
|
|
brew home
|
2009-10-26 18:20:18 +00:00
|
|
|
EOS
|
2009-08-10 16:27:24 +01:00
|
|
|
end
|
2009-09-04 15:22:25 -07:00
|
|
|
|
2010-03-09 02:09:46 +00:00
|
|
|
def resolve_alias name
|
|
|
|
aka = HOMEBREW_REPOSITORY+"Library/Aliases/#{name}"
|
|
|
|
if aka.file?
|
|
|
|
aka.realpath.basename('.rb').to_s
|
|
|
|
else
|
|
|
|
name
|
|
|
|
end
|
2009-08-11 00:27:18 +01:00
|
|
|
end
|
2010-08-07 22:15:29 -07:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def downcased_unique_named
|
2010-08-08 05:00:47 -07:00
|
|
|
@downcased_unique_named ||= named.map{|arg| arg.downcase}.uniq
|
2010-08-07 22:15:29 -07:00
|
|
|
end
|
2009-08-10 16:27:24 +01:00
|
|
|
end
|