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
commitef1e9b1a8c4e9bd824a0c06c73472e4c0f905f69 (patch)
tree116d57264a608892ccf6859e64dd39a6e177469f /Library
parent1f4081ee831f969be2bb4c7023de215478db4ac7 (diff)
downloadhomebrew-ef1e9b1a8c4e9bd824a0c06c73472e4c0f905f69.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