brew: check for --help and friends in more of ARGV
Let's check for e.g. --help anywhere in the ARGV array rather than just the first value to avoid brew upgrade --help causing problems. Closes Homebrew/homebrew#26675. Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
This commit is contained in:
parent
a7b515e503
commit
eabe9dc6d0
@ -157,6 +157,14 @@ module HomebrewArgvExtension
|
|||||||
include? '--force-bottle'
|
include? '--force-bottle'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def help?
|
||||||
|
empty? || grep(/(-h|--help|--usage|-\?|help)/).any?
|
||||||
|
end
|
||||||
|
|
||||||
|
def version?
|
||||||
|
include? '--version'
|
||||||
|
end
|
||||||
|
|
||||||
# eg. `foo -ns -i --bar` has three switches, n, s and i
|
# eg. `foo -ns -i --bar` has three switches, n, s and i
|
||||||
def switch? switch_character
|
def switch? switch_character
|
||||||
return false if switch_character.length > 1
|
return false if switch_character.length > 1
|
||||||
|
|||||||
@ -16,14 +16,14 @@ $:.unshift(HOMEBREW_LIBRARY_PATH + '/vendor')
|
|||||||
$:.unshift(HOMEBREW_LIBRARY_PATH)
|
$:.unshift(HOMEBREW_LIBRARY_PATH)
|
||||||
require 'global'
|
require 'global'
|
||||||
|
|
||||||
case ARGV.first when '-h', '--help', '--usage', '-?', 'help', nil
|
if ARGV.help?
|
||||||
require 'cmd/help'
|
require 'cmd/help'
|
||||||
puts Homebrew.help_s
|
puts ARGV.usage
|
||||||
exit ARGV.first ? 0 : 1
|
exit ARGV.any? ? 0 : 1
|
||||||
when '--version'
|
elsif ARGV.version?
|
||||||
puts HOMEBREW_VERSION
|
puts HOMEBREW_VERSION
|
||||||
exit 0
|
exit 0
|
||||||
when '-v'
|
elsif ARGV.first == '-v'
|
||||||
puts "Homebrew #{HOMEBREW_VERSION}"
|
puts "Homebrew #{HOMEBREW_VERSION}"
|
||||||
# Shift the -v to the end of the parameter list
|
# Shift the -v to the end of the parameter list
|
||||||
ARGV << ARGV.shift
|
ARGV << ARGV.shift
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user