Raise if ARGV.named and no named arguments
This commit is contained in:
parent
8c7b6a947c
commit
3b262d0b23
@ -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 @@ Usage: brew [--verbose]
|
||||
|
||||
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
|
||||
|
13
bin/brew
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user