optparse.rb: case-sensitive candidate
* lib/optparse.rb (candidate): short options are case-sensitive by the default, should not match case-different options.. https://github.com/mernen/completion-ruby/pull/9#issuecomment-317287946 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59412 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
bb52d2be40
commit
3fe5d355a8
@ -1744,16 +1744,16 @@ XXX
|
|||||||
def candidate(word)
|
def candidate(word)
|
||||||
list = []
|
list = []
|
||||||
case word
|
case word
|
||||||
|
when '-'
|
||||||
|
long = short = true
|
||||||
when /\A--/
|
when /\A--/
|
||||||
word, arg = word.split(/=/, 2)
|
word, arg = word.split(/=/, 2)
|
||||||
argpat = Completion.regexp(arg, false) if arg and !arg.empty?
|
argpat = Completion.regexp(arg, false) if arg and !arg.empty?
|
||||||
long = true
|
long = true
|
||||||
when /\A-(!-)/
|
|
||||||
short = true
|
|
||||||
when /\A-/
|
when /\A-/
|
||||||
long = short = true
|
short = true
|
||||||
end
|
end
|
||||||
pat = Completion.regexp(word, true)
|
pat = Completion.regexp(word, long)
|
||||||
visit(:each_option) do |opt|
|
visit(:each_option) do |opt|
|
||||||
next unless Switch === opt
|
next unless Switch === opt
|
||||||
opts = (long ? opt.long : []) + (short ? opt.short : [])
|
opts = (long ? opt.long : []) + (short ? opt.short : [])
|
||||||
|
@ -40,4 +40,9 @@ class TestOptionParser::BashCompletion < Test::Unit::TestCase
|
|||||||
def test_long_for_option_complete
|
def test_long_for_option_complete
|
||||||
assert_equal(%w[hello help], @opt.candidate("--for=h"))
|
assert_equal(%w[hello help], @opt.candidate("--for=h"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_case_sensitive
|
||||||
|
@opt.define("-Z") {}
|
||||||
|
assert_equal(%w[-z], @opt.candidate("-z"))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user