Proper single character switch handling
Includes a test. So now you can do `brew cleanup -ns` and it will work.
This commit is contained in:
parent
9c5ddb5721
commit
b63ec18564
@ -103,6 +103,16 @@ module HomebrewArgvExtension
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# eg. `foo -ns -i --bar` has three switches, n, s and i
|
||||||
|
def switch? switch_character
|
||||||
|
return false if switch_character.length > 1
|
||||||
|
options_only.each do |arg|
|
||||||
|
next if arg[1..1] == '-'
|
||||||
|
return true if arg.include? switch_character
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
def usage
|
def usage
|
||||||
require 'cmd/help'
|
require 'cmd/help'
|
||||||
Homebrew.help_s
|
Homebrew.help_s
|
||||||
|
|||||||
@ -29,5 +29,20 @@ class ARGVTests < Test::Unit::TestCase
|
|||||||
assert_equal 1, ARGV.kegs.length
|
assert_equal 1, ARGV.kegs.length
|
||||||
assert_raises(FormulaUnavailableError) { ARGV.formulae }
|
assert_raises(FormulaUnavailableError) { ARGV.formulae }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_switch?
|
||||||
|
ARGV.reset
|
||||||
|
ARGV.unshift "-ns"
|
||||||
|
ARGV.unshift "-i"
|
||||||
|
ARGV.unshift "--bar"
|
||||||
|
assert ARGV.switch?('n')
|
||||||
|
assert ARGV.switch?('s')
|
||||||
|
assert ARGV.switch?('i')
|
||||||
|
assert !ARGV.switch?('b')
|
||||||
|
assert !ARGV.switch?('ns')
|
||||||
|
assert !ARGV.switch?('bar')
|
||||||
|
assert !ARGV.switch?('--bar')
|
||||||
|
assert !ARGV.switch?('-n')
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user