aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/ARGV+yeast.rb
blob: 92d3412545ab8ae269acbafc9d24221da5a9ca35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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