2009-08-31 16:01:36 +01:00
|
|
|
# Copyright 2009 Max Howell and other contributors.
|
2009-08-10 16:27:24 +01:00
|
|
|
#
|
2009-08-31 16:01:36 +01:00
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
2009-08-10 16:27:24 +01:00
|
|
|
#
|
2009-08-31 16:01:36 +01:00
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
2009-08-10 16:27:24 +01:00
|
|
|
#
|
2009-08-31 16:01:36 +01:00
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2009-08-10 16:27:24 +01:00
|
|
|
#
|
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
|
|
|
|
def options
|
|
|
|
select {|arg| arg[0..0] == '-'}
|
|
|
|
end
|
|
|
|
def formulae
|
|
|
|
require 'formula'
|
2009-10-24 18:09:43 +01:00
|
|
|
@formulae ||= downcased_unique_named.collect {|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
|
|
|
|
def kegs
|
|
|
|
require 'keg'
|
2009-10-24 18:09:43 +01:00
|
|
|
@kegs ||= downcased_unique_named.collect do |name|
|
2009-08-10 16:27:24 +01:00
|
|
|
d=HOMEBREW_CELLAR+name
|
|
|
|
raise "#{name} is not installed" if not d.directory? or d.children.length == 0
|
|
|
|
raise "#{name} has multiple installed versions" if d.children.length > 1
|
|
|
|
Keg.new d.children[0]
|
|
|
|
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
|
|
|
|
at @n+1
|
|
|
|
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
|
2009-08-10 16:27:24 +01:00
|
|
|
|
|
|
|
def flag? flag
|
|
|
|
options.each do |arg|
|
|
|
|
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
|
|
|
|
2009-08-10 16:27:24 +01:00
|
|
|
def usage
|
|
|
|
<<-EOS
|
|
|
|
Usage: brew command [formula] ...
|
2009-09-22 19:58:10 +01:00
|
|
|
Usage: brew [--prefix] [--cache] [--version|-v]
|
2009-09-05 16:22:06 +01:00
|
|
|
Usage: brew [--verbose|-v]
|
2009-08-10 16:27:24 +01:00
|
|
|
|
|
|
|
Commands:
|
2009-10-26 18:20:36 +00:00
|
|
|
install formula ... [--ignore-dependencies]
|
2009-08-11 00:27:18 +01:00
|
|
|
remove formula ...
|
2009-09-17 16:06:56 -07:00
|
|
|
search [/regex/] [substring]
|
2009-09-25 19:04:34 +12:00
|
|
|
list [--brewed] [--unbrewed] [formula] ...
|
2009-08-11 00:27:18 +01:00
|
|
|
link formula ...
|
2009-09-24 19:19:57 +01:00
|
|
|
unlink formula ...
|
2009-08-11 00:27:18 +01:00
|
|
|
home formula ...
|
2009-08-10 16:27:24 +01:00
|
|
|
info [formula] [--github]
|
|
|
|
prune
|
2009-09-08 00:07:03 +02:00
|
|
|
update
|
2009-09-04 15:22:25 -07:00
|
|
|
|
2009-09-24 19:19:57 +01:00
|
|
|
Commands useful when contributing:
|
|
|
|
log formula
|
|
|
|
create URL
|
2009-09-25 14:25:09 +02:00
|
|
|
edit [formula]
|
2009-10-26 18:20:36 +00:00
|
|
|
install formula [--debug|-d] [--interactive|-i] [--verbose|-v]
|
2009-09-24 19:19:57 +01:00
|
|
|
|
2009-08-23 13:38:26 +01: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
|
|
|
|
2009-10-26 18:20:18 +00:00
|
|
|
private
|
|
|
|
|
2009-10-24 18:09:43 +01:00
|
|
|
def downcased_unique_named
|
2009-10-26 18:20:18 +00:00
|
|
|
@downcased_unique_named ||= named.collect{|arg| arg.downcase}.uniq
|
2009-08-11 00:27:18 +01:00
|
|
|
end
|
2009-08-10 16:27:24 +01:00
|
|
|
end
|