aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMax Howell2009-08-10 16:27:24 +0100
committerMax Howell2009-08-10 16:27:24 +0100
commitb32d2044c599db400b3332fef09f4008c813c58d (patch)
tree49639a63282c0dd615f1ee5f23e6f5011174165f /Library
parentcae0e78e6065b95ce2fc47d0d2cdd500945ffe6d (diff)
downloadbrew-b32d2044c599db400b3332fef09f4008c813c58d.tar.bz2
ARGV+yeast
Extensions to ARGV that are convenient or improve our robustness
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/ARGV+yeast.rb84
1 files changed, 84 insertions, 0 deletions
diff --git a/Library/Homebrew/ARGV+yeast.rb b/Library/Homebrew/ARGV+yeast.rb
new file mode 100644
index 000000000..92d341254
--- /dev/null
+++ b/Library/Homebrew/ARGV+yeast.rb
@@ -0,0 +1,84 @@
+# Copyright 2009 Max Howell <max@methylblue.com>
+#
+# This file is part of Homebrew.
+#
+# Homebrew is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Homebrew is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Homebrew. If not, see <http://www.gnu.org/licenses/>.
+#
+module HomebrewArgvExtension
+ def named
+ reject {|arg| arg[0..0] == '-'}
+ end
+ def options
+ select {|arg| arg[0..0] == '-'}
+ end
+ def formulae
+ require 'formula'
+ named.collect {|name| Formula.factory name}
+ end
+ def kegs
+ require 'keg'
+ named.collect do |name|
+ 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
+ end
+
+ # self documenting perhaps?
+ def include? arg
+ @n=index arg
+ end
+ def next
+ at @n+1
+ end
+
+ def force?
+ flag? '--force'
+ end
+ def verbose?
+ flag? '--verbose'
+ end
+ def debug?
+ flag? '--debug' or ENV['HOMEBREW_DEBUG']
+ end
+
+ 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
+
+ def usage
+ <<-EOS
+Usage: brew command [formula] ...
+Usage: brew [--prefix] [--cache] [--version]
+Usage: brew [--verbose]
+
+Commands:
+ install formula ... [--debug] [--interactive]
+ rm formula ...
+ list formula ...
+ ln formula ...
+ info [formula] [--github]
+ mk url
+ prune
+ EOS
+ end
+end
+
+ARGV.extend HomebrewArgvExtension