[ruby/optparse] Allow non-string enum list #79
Command line arguments are strings, convert enum list elements to strings to match. https://github.com/ruby/optparse/commit/c5ec052efc
This commit is contained in:
parent
213c27825a
commit
cdf36d6bfd
@ -1503,7 +1503,7 @@ XXX
|
||||
else
|
||||
raise ArgumentError, "argument pattern given twice"
|
||||
end
|
||||
o.each {|pat, *v| pattern[pat] = v.fetch(0) {pat}}
|
||||
o.each {|pat, *v| pattern[pat.to_s] = v.fetch(0) {pat}}
|
||||
when Module
|
||||
raise ArgumentError, "unsupported argument type: #{o}", ParseError.filter_backtrace(caller(4))
|
||||
when *ArgumentStyle.keys
|
||||
|
@ -8,6 +8,7 @@ class TestOptionParserPlaceArg < TestOptionParser
|
||||
@opt.def_option("--option [VAL]") {|x| @flag = x}
|
||||
@opt.def_option("-T [level]", /^[0-4]$/, Integer) {|x| @topt = x}
|
||||
@opt.def_option("--enum [VAL]", [:Alpha, :Bravo, :Charlie]) {|x| @enum = x}
|
||||
@opt.def_option("--integer [VAL]", [1, 2, 3]) {|x| @integer = x}
|
||||
@topt = nil
|
||||
@opt.def_option("-n") {}
|
||||
@opt.def_option("--regexp [REGEXP]", Regexp) {|x| @reopt = x}
|
||||
@ -99,4 +100,9 @@ class TestOptionParserPlaceArg < TestOptionParser
|
||||
assert_equal([], no_error {@opt.parse!(%w"--enum=A")})
|
||||
assert_equal(:Alpha, @enum)
|
||||
end
|
||||
|
||||
def test_enum_conversion
|
||||
assert_equal([], no_error {@opt.parse!(%w"--integer=1")})
|
||||
assert_equal(1, @integer)
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user