summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-11-17 01:50:31 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-11-17 01:50:31 +0000
commitc00dde0174d24df37aeacbefc99921a0d5352a9d (patch)
tree28200fde07a585d7d20aaa2163a5f10a989ed298 /lib
parent3602c6d258480096ad9b46cce20459a9af515ddf (diff)
downloadruby-c00dde0174d24df37aeacbefc99921a0d5352a9d.tar.gz
ruby-c00dde0174d24df37aeacbefc99921a0d5352a9d.tar.xz
ruby-c00dde0174d24df37aeacbefc99921a0d5352a9d.zip
* lib/optparse.rb (OptionParser::Completion::complete): allow least
common completion for three or more candidates. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@4972 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/optparse.rb15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/optparse.rb b/lib/optparse.rb
index c00b152a2..50da8b329 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