Browse files

Raise if ARGV.named and no named arguments

  • Loading branch information...
1 parent ea2f9bb commit ea7c8915a2885f3c544cfd63594dacf2144874ca @mxcl mxcl committed Aug 10, 2009
Showing with 24 additions and 9 deletions.
  1. +16 −4 Library/Homebrew/ARGV+yeast.rb
  2. +8 −5 bin/brew
View
20 Library/Homebrew/ARGV+yeast.rb
@@ -17,7 +17,11 @@
#
module HomebrewArgvExtension
def named
- reject{|arg| arg[0..0] == '-'}.collect{|arg| arg.downcase}.uniq
+ nn=namedp
+ raise UsageError if nn.empty?
+ end
+ def named_empty?
+ namedp.empty?
end
def options
select {|arg| arg[0..0] == '-'}
@@ -71,14 +75,22 @@ def usage
Commands:
install formula ... [--debug] [--interactive]
- rm formula ...
+ remove formula ...
list formula ...
- ln formula ...
+ link formula ...
+ home formula ...
info [formula] [--github]
- mk url
+ make url
prune
EOS
end
+
+private
+ def namedp
+ nn=reject{|arg| arg[0..0] == '-'}.collect{|arg| arg.downcase}.uniq
+ end
end
+class UsageError <RuntimeError; end
+
ARGV.extend HomebrewArgvExtension
View
13 bin/brew
@@ -33,17 +33,17 @@ begin
when '-v', '--version' then puts HOMEBREW_VERSION
when 'home', 'homepage'
- if ARGV.named.empty?
+ if ARGV.named_empty?
exec "open", HOMEBREW_WWW
else
exec "open", *ARGV.formulae.collect {|f| f.homepage}
end
when 'ls', 'list'
- exec "find", *ARGV.kegs.concat(%w[-not -type d -print])
+ exec "find", *ARGV.kegs+%w[-not -type d -print]
when 'edit'
- if ARGV.empty?
+ if ARGV.named_empty?
exec "mate", *Dir["#{HOMEBREW_PREFIX}/Library/*"]<<
"#{HOMEBREW_PREFIX}/bin/brew"<<
"#{HOMEBREW_PREFIX}/README"
@@ -61,7 +61,7 @@ begin
else
Process.wait pid
end
- exit! 1 if $? != 0 # exception in other brew will be visible on screen
+ exit! $? if $? != 0 # exception in other brew will be visible on screen
end
# this is an internal option, don't expose it to the user
@@ -110,7 +110,7 @@ begin
end
when 'info', 'abv'
- if ARGV.named.empty?
+ if ARGV.named_empty?
puts `ls #{HOMEBREW_CELLAR} | wc -l`.strip+" kegs, "+HOMEBREW_CELLAR.abv
elsif ARGV[0][0..6] == 'http://'
puts Pathname.new(ARGV.shift).version
@@ -122,6 +122,9 @@ begin
puts ARGV.usage
end
+rescue UsageError
+ onoe "Invalid usage"
+ puts ARGV.usage
rescue SystemExit
ohai "Kernel.exit" if ARGV.verbose?
rescue Interrupt => e

0 comments on commit ea7c891

Please sign in to comment.