[ruby/optparse] Fix require_exact
to work with options defined as --[no]-something
https://github.com/ruby/optparse/commit/4e346ad337
This commit is contained in:
parent
50bcaa6286
commit
f7a407cabd
@ -1048,7 +1048,7 @@ XXX
|
|||||||
# Shows option summary.
|
# Shows option summary.
|
||||||
#
|
#
|
||||||
Officious['help'] = proc do |parser|
|
Officious['help'] = proc do |parser|
|
||||||
Switch::NoArgument.new do |arg|
|
Switch::NoArgument.new(nil, nil, ["-h"], ["--help"]) do |arg|
|
||||||
puts parser.help
|
puts parser.help
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
@ -1473,7 +1473,7 @@ XXX
|
|||||||
default_style = default_style.guess(arg = a)
|
default_style = default_style.guess(arg = a)
|
||||||
default_pattern, conv = search(:atype, o) unless default_pattern
|
default_pattern, conv = search(:atype, o) unless default_pattern
|
||||||
end
|
end
|
||||||
ldesc << "--[no-]#{q}"
|
ldesc << "--#{q}" << "--no-#{q}"
|
||||||
(o = q.downcase).tr!('_', '-')
|
(o = q.downcase).tr!('_', '-')
|
||||||
long << o
|
long << o
|
||||||
not_pattern, not_conv = search(:atype, FalseClass) unless not_style
|
not_pattern, not_conv = search(:atype, FalseClass) unless not_style
|
||||||
@ -1649,7 +1649,7 @@ XXX
|
|||||||
opt.tr!('_', '-')
|
opt.tr!('_', '-')
|
||||||
begin
|
begin
|
||||||
sw, = complete(:long, opt, true)
|
sw, = complete(:long, opt, true)
|
||||||
if require_exact && !sw.long.include?(arg)
|
if require_exact && !sw.long.include?("--#{opt}")
|
||||||
throw :terminate, arg unless raise_unknown
|
throw :terminate, arg unless raise_unknown
|
||||||
raise InvalidOption, arg
|
raise InvalidOption, arg
|
||||||
end
|
end
|
||||||
|
@ -88,9 +88,9 @@ class TestOptionParser < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
@opt.require_exact = true
|
@opt.require_exact = true
|
||||||
%w(--zrs -F -Ffoo).each do |arg|
|
[%w(--zrs foo), %w(--zrs=foo), %w(-F foo), %w(-Ffoo)].each do |args|
|
||||||
result = {}
|
result = {}
|
||||||
@opt.parse([arg, 'foo'], into: result)
|
@opt.parse(args, into: result)
|
||||||
assert_equal({zrs: 'foo'}, result)
|
assert_equal({zrs: 'foo'}, result)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -99,6 +99,14 @@ class TestOptionParser < Test::Unit::TestCase
|
|||||||
assert_raise(OptionParser::InvalidOption) {@opt.parse(%w(-zrs foo))}
|
assert_raise(OptionParser::InvalidOption) {@opt.parse(%w(-zrs foo))}
|
||||||
assert_raise(OptionParser::InvalidOption) {@opt.parse(%w(-zr foo))}
|
assert_raise(OptionParser::InvalidOption) {@opt.parse(%w(-zr foo))}
|
||||||
assert_raise(OptionParser::InvalidOption) {@opt.parse(%w(-z foo))}
|
assert_raise(OptionParser::InvalidOption) {@opt.parse(%w(-z foo))}
|
||||||
|
|
||||||
|
@opt.def_option('-f', '--[no-]foo', 'foo') {|arg| @foo = arg}
|
||||||
|
@opt.parse(%w[-f])
|
||||||
|
assert_equal(true, @foo)
|
||||||
|
@opt.parse(%w[--foo])
|
||||||
|
assert_equal(true, @foo)
|
||||||
|
@opt.parse(%w[--no-foo])
|
||||||
|
assert_equal(false, @foo)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_raise_unknown
|
def test_raise_unknown
|
||||||
|
Loading…
x
Reference in New Issue
Block a user