diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-11-17 01:50:31 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-11-17 01:50:31 +0000 |
commit | bc94ec8f4c1b903236171c8b3cd062e3684514b8 (patch) | |
tree | 28200fde07a585d7d20aaa2163a5f10a989ed298 /lib/optparse.rb | |
parent | 2d3a489f6dacd5c68ba1eeb99499f7c99ffe5a3d (diff) | |
download | ruby-bc94ec8f4c1b903236171c8b3cd062e3684514b8.tar.gz |
* lib/optparse.rb (OptionParser::Completion::complete): allow least
common completion for three or more candidates.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4972 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/optparse.rb')
-rw-r--r-- | lib/optparse.rb | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/optparse.rb b/lib/optparse.rb index c00b152a21..50da8b329d 100644 --- a/lib/optparse.rb +++ b/lib/optparse.rb @@ -83,6 +83,7 @@ Keyword completion module. pat ||= Regexp.new('\A' + Regexp.quote(key).gsub(/\w+(?=.)/, '\&\w*'), ignore_case?) canon, sw, k, v, cn = nil + candidates = [] each do |k, *v| (if Regexp === k kn = nil @@ -92,14 +93,20 @@ Keyword completion module. pat === kn end) or next v << k if v.empty? - if !canon - canon, sw, cn = k, v, kn - elsif sw != v + candidates << [k, v, kn] + end + candidates = candidates.sort_by {|k, v, kn| kn.size} + if candidates.size == 1 + canon, sw, * = candidates[0] + elsif candidates.size > 1 + canon, sw, cn = candidates.shift + candidates.each do |k, v, kn| + next if sw == v if String === cn and String === kn if cn.rindex(kn, 0) canon, sw, cn = k, v, kn next - elsif kn.rindex(canon, 0) + elsif kn.rindex(cn, 0) next end end |