Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Raise if ARGV.named and no named arguments

  • Loading branch information...
commit ea7c8915a2885f3c544cfd63594dacf2144874ca 1 parent ea2f9bb
Max Howell mxcl authored

Showing 2 changed files with 24 additions and 9 deletions. Show diff stats Hide diff stats

  1. +16 4 Library/Homebrew/ARGV+yeast.rb
  2. +8 5 bin/brew
20 Library/Homebrew/ARGV+yeast.rb
@@ -17,7 +17,11 @@
17 17 #
18 18 module HomebrewArgvExtension
19 19 def named
20   - reject{|arg| arg[0..0] == '-'}.collect{|arg| arg.downcase}.uniq
  20 + nn=namedp
  21 + raise UsageError if nn.empty?
  22 + end
  23 + def named_empty?
  24 + namedp.empty?
21 25 end
22 26 def options
23 27 select {|arg| arg[0..0] == '-'}
@@ -71,14 +75,22 @@ def usage
71 75
72 76 Commands:
73 77 install formula ... [--debug] [--interactive]
74   - rm formula ...
  78 + remove formula ...
75 79 list formula ...
76   - ln formula ...
  80 + link formula ...
  81 + home formula ...
77 82 info [formula] [--github]
78   - mk url
  83 + make url
79 84 prune
80 85 EOS
81 86 end
  87 +
  88 +private
  89 + def namedp
  90 + nn=reject{|arg| arg[0..0] == '-'}.collect{|arg| arg.downcase}.uniq
  91 + end
82 92 end
83 93
  94 +class UsageError <RuntimeError; end
  95 +
84 96 ARGV.extend HomebrewArgvExtension
13 bin/brew
@@ -33,17 +33,17 @@ begin
33 33 when '-v', '--version' then puts HOMEBREW_VERSION
34 34
35 35 when 'home', 'homepage'
36   - if ARGV.named.empty?
  36 + if ARGV.named_empty?
37 37 exec "open", HOMEBREW_WWW
38 38 else
39 39 exec "open", *ARGV.formulae.collect {|f| f.homepage}
40 40 end
41 41
42 42 when 'ls', 'list'
43   - exec "find", *ARGV.kegs.concat(%w[-not -type d -print])
  43 + exec "find", *ARGV.kegs+%w[-not -type d -print]
44 44
45 45 when 'edit'
46   - if ARGV.empty?
  46 + if ARGV.named_empty?
47 47 exec "mate", *Dir["#{HOMEBREW_PREFIX}/Library/*"]<<
48 48 "#{HOMEBREW_PREFIX}/bin/brew"<<
49 49 "#{HOMEBREW_PREFIX}/README"
@@ -61,7 +61,7 @@ begin
61 61 else
62 62 Process.wait pid
63 63 end
64   - exit! 1 if $? != 0 # exception in other brew will be visible on screen
  64 + exit! $? if $? != 0 # exception in other brew will be visible on screen
65 65 end
66 66
67 67 # this is an internal option, don't expose it to the user
@@ -110,7 +110,7 @@ begin
110 110 end
111 111
112 112 when 'info', 'abv'
113   - if ARGV.named.empty?
  113 + if ARGV.named_empty?
114 114 puts `ls #{HOMEBREW_CELLAR} | wc -l`.strip+" kegs, "+HOMEBREW_CELLAR.abv
115 115 elsif ARGV[0][0..6] == 'http://'
116 116 puts Pathname.new(ARGV.shift).version
@@ -122,6 +122,9 @@ begin
122 122 puts ARGV.usage
123 123 end
124 124
  125 +rescue UsageError
  126 + onoe "Invalid usage"
  127 + puts ARGV.usage
125 128 rescue SystemExit
126 129 ohai "Kernel.exit" if ARGV.verbose?
127 130 rescue Interrupt => e

0 comments on commit ea7c891

Please sign in to comment.
Something went wrong with that request. Please try again.