Raise if ARGV.named and no named arguments
This commit is contained in:
parent
8c7b6a947c
commit
3b262d0b23
@ -17,7 +17,11 @@
|
|||||||
#
|
#
|
||||||
module HomebrewArgvExtension
|
module HomebrewArgvExtension
|
||||||
def named
|
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
|
end
|
||||||
def options
|
def options
|
||||||
select {|arg| arg[0..0] == '-'}
|
select {|arg| arg[0..0] == '-'}
|
||||||
@ -71,14 +75,22 @@ Usage: brew [--verbose]
|
|||||||
|
|
||||||
Commands:
|
Commands:
|
||||||
install formula ... [--debug] [--interactive]
|
install formula ... [--debug] [--interactive]
|
||||||
rm formula ...
|
remove formula ...
|
||||||
list formula ...
|
list formula ...
|
||||||
ln formula ...
|
link formula ...
|
||||||
|
home formula ...
|
||||||
info [formula] [--github]
|
info [formula] [--github]
|
||||||
mk url
|
make url
|
||||||
prune
|
prune
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def namedp
|
||||||
|
nn=reject{|arg| arg[0..0] == '-'}.collect{|arg| arg.downcase}.uniq
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class UsageError <RuntimeError; end
|
||||||
|
|
||||||
ARGV.extend HomebrewArgvExtension
|
ARGV.extend HomebrewArgvExtension
|
||||||
|
13
bin/brew
13
bin/brew
@ -33,17 +33,17 @@ begin
|
|||||||
when '-v', '--version' then puts HOMEBREW_VERSION
|
when '-v', '--version' then puts HOMEBREW_VERSION
|
||||||
|
|
||||||
when 'home', 'homepage'
|
when 'home', 'homepage'
|
||||||
if ARGV.named.empty?
|
if ARGV.named_empty?
|
||||||
exec "open", HOMEBREW_WWW
|
exec "open", HOMEBREW_WWW
|
||||||
else
|
else
|
||||||
exec "open", *ARGV.formulae.collect {|f| f.homepage}
|
exec "open", *ARGV.formulae.collect {|f| f.homepage}
|
||||||
end
|
end
|
||||||
|
|
||||||
when 'ls', 'list'
|
when 'ls', 'list'
|
||||||
exec "find", *ARGV.kegs.concat(%w[-not -type d -print])
|
exec "find", *ARGV.kegs+%w[-not -type d -print]
|
||||||
|
|
||||||
when 'edit'
|
when 'edit'
|
||||||
if ARGV.empty?
|
if ARGV.named_empty?
|
||||||
exec "mate", *Dir["#{HOMEBREW_PREFIX}/Library/*"]<<
|
exec "mate", *Dir["#{HOMEBREW_PREFIX}/Library/*"]<<
|
||||||
"#{HOMEBREW_PREFIX}/bin/brew"<<
|
"#{HOMEBREW_PREFIX}/bin/brew"<<
|
||||||
"#{HOMEBREW_PREFIX}/README"
|
"#{HOMEBREW_PREFIX}/README"
|
||||||
@ -61,7 +61,7 @@ begin
|
|||||||
else
|
else
|
||||||
Process.wait pid
|
Process.wait pid
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
# this is an internal option, don't expose it to the user
|
# this is an internal option, don't expose it to the user
|
||||||
@ -110,7 +110,7 @@ begin
|
|||||||
end
|
end
|
||||||
|
|
||||||
when 'info', 'abv'
|
when 'info', 'abv'
|
||||||
if ARGV.named.empty?
|
if ARGV.named_empty?
|
||||||
puts `ls #{HOMEBREW_CELLAR} | wc -l`.strip+" kegs, "+HOMEBREW_CELLAR.abv
|
puts `ls #{HOMEBREW_CELLAR} | wc -l`.strip+" kegs, "+HOMEBREW_CELLAR.abv
|
||||||
elsif ARGV[0][0..6] == 'http://'
|
elsif ARGV[0][0..6] == 'http://'
|
||||||
puts Pathname.new(ARGV.shift).version
|
puts Pathname.new(ARGV.shift).version
|
||||||
@ -122,6 +122,9 @@ begin
|
|||||||
puts ARGV.usage
|
puts ARGV.usage
|
||||||
end
|
end
|
||||||
|
|
||||||
|
rescue UsageError
|
||||||
|
onoe "Invalid usage"
|
||||||
|
puts ARGV.usage
|
||||||
rescue SystemExit
|
rescue SystemExit
|
||||||
ohai "Kernel.exit" if ARGV.verbose?
|
ohai "Kernel.exit" if ARGV.verbose?
|
||||||
rescue Interrupt => e
|
rescue Interrupt => e
|
||||||
|
Loading…
x
Reference in New Issue
Block a user