aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMax Howell2010-09-25 12:49:09 +0100
committerAdam Vandenberg2011-03-12 11:55:04 -0800
commit9f451154ea8a1527ed826e0624b4bd592bb34492 (patch)
tree21edd7f3ff2e3142651a3182ecdb86c0890ca5f5 /Library
parentc67a372c576dad61cf864fdb93bd92648c6513af (diff)
downloadhomebrew-9f451154ea8a1527ed826e0624b4bd592bb34492.tar.bz2
`brew deps foo bar` now gives the dependency intersection
Rationale: this is more useful than the union, and you can still easily get the union by running the command twice and concatenating the result.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/cmd/deps.rb24
-rw-r--r--Library/Homebrew/extend/ARGV.rb3
2 files changed, 20 insertions, 7 deletions
diff --git a/Library/Homebrew/cmd/deps.rb b/Library/Homebrew/cmd/deps.rb
index 2e9a723f4..f5dd675c8 100644
--- a/Library/Homebrew/cmd/deps.rb
+++ b/Library/Homebrew/cmd/deps.rb
@@ -1,14 +1,24 @@
+require 'formula'
+
module Homebrew extend self
def deps
- puts if ARGV.include?('--all')
- require 'formula'
- Formula.all.each do |f|
- "#{f.name}:#{f.deps.join(' ')}"
+ if ARGV.include? '--all'
+ Formula.each do |f|
+ # TODO add a space after the colon??
+ puts "#{f.name}:#{f.deps*' '}"
end
- elsif ARGV.include?("-1") or ARGV.include?("--1")
- *ARGV.formulae.map{ |f| f.deps or [] }.flatten.uniq.sort
else
- *ARGV.formulae.map{ |f| f.recursive_deps.map{ |f| f.name } }.flatten.uniq.sort
+ func = if ARGV.one? then :deps else :recursive_deps end
+ puts ARGV.formulae.map(&func).intersection.sort
end
end
end
+
+class Array
+ def intersection
+ a = []
+ each{ |b| a |= b }
+ each{ |c| a &= c }
+ a
+ end
+end
diff --git a/Library/Homebrew/extend/ARGV.rb b/Library/Homebrew/extend/ARGV.rb
index c7195bbcd..29d2c1d19 100644
--- a/Library/Homebrew/extend/ARGV.rb
+++ b/Library/Homebrew/extend/ARGV.rb
@@ -54,6 +54,9 @@ module HomebrewArgvExtension
def build_head?
flag? '--HEAD'
end
+ def one?
+ flag? "--1"
+ end
def flag? flag
options_only.each do |arg|