mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/optparse.rb (OptionParser::Completion#complete): prior shorter
name to containing longer name. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4947 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c90fab98a2
commit
87bb4b5468
2 changed files with 24 additions and 13 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Thu Nov 13 11:31:14 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* lib/optparse.rb (OptionParser::Completion#complete): prior shorter
|
||||||
|
name to containing longer name.
|
||||||
|
|
||||||
Thu Nov 13 06:08:54 2003 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
|
Thu Nov 13 06:08:54 2003 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
|
||||||
|
|
||||||
* ext/tk/lib/tk.rb: stop freezing some classes
|
* ext/tk/lib/tk.rb: stop freezing some classes
|
||||||
|
|
|
@ -82,18 +82,28 @@ Keyword completion module.
|
||||||
def complete(key, pat = nil)
|
def complete(key, pat = nil)
|
||||||
pat ||= Regexp.new('\A' + Regexp.quote(key).gsub(/\w+(?=.)/, '\&\w*'),
|
pat ||= Regexp.new('\A' + Regexp.quote(key).gsub(/\w+(?=.)/, '\&\w*'),
|
||||||
ignore_case?)
|
ignore_case?)
|
||||||
canon, sw, k, v = nil
|
canon, sw, k, v, cn = nil
|
||||||
each do |k, *v|
|
each do |k, *v|
|
||||||
(if Regexp === k
|
(if Regexp === k
|
||||||
|
kn = nil
|
||||||
k === key
|
k === key
|
||||||
else
|
else
|
||||||
pat === (defined?(k.id2name) ? k.id2name : k)
|
kn = defined?(k.id2name) ? k.id2name : k
|
||||||
|
pat === kn
|
||||||
end) or next
|
end) or next
|
||||||
v << k if v.empty?
|
v << k if v.empty?
|
||||||
unless canon
|
if !canon
|
||||||
canon, sw = k, v
|
canon, sw, cn = k, v, kn
|
||||||
else
|
elsif sw != v
|
||||||
throw :ambiguous, key unless 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)
|
||||||
|
next
|
||||||
|
end
|
||||||
|
end
|
||||||
|
throw :ambiguous, key
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if canon
|
if canon
|
||||||
|
@ -564,7 +574,7 @@ summary feature.
|
||||||
def match(key)
|
def match(key)
|
||||||
return key, *fetch(key) {
|
return key, *fetch(key) {
|
||||||
raise AmbiguousArgument, catch(:ambiguous) {return complete(key)}
|
raise AmbiguousArgument, catch(:ambiguous) {return complete(key)}
|
||||||
}.to_a
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -995,11 +1005,7 @@ Default options, which never appear in option summary.
|
||||||
else
|
else
|
||||||
raise ArgumentError, "argument pattern given twice"
|
raise ArgumentError, "argument pattern given twice"
|
||||||
end
|
end
|
||||||
if Array === o
|
o.each {|(o, *v)| pattern[o] = v.fetch(0) {o}}
|
||||||
o.each {|o| pattern[(Array === o ? o[0] : o)] = o}
|
|
||||||
else
|
|
||||||
pattern.update(o)
|
|
||||||
end
|
|
||||||
when Module
|
when Module
|
||||||
raise ArgumentError, "unsupported argument type: #{o}"
|
raise ArgumentError, "unsupported argument type: #{o}"
|
||||||
when *ArgumentStyle.keys
|
when *ArgumentStyle.keys
|
||||||
|
@ -1191,7 +1197,7 @@ Default options, which never appear in option summary.
|
||||||
argv.unshift(opt) if opt and (opt = opt.sub(/\A-*/, '-')) != '-'
|
argv.unshift(opt) if opt and (opt = opt.sub(/\A-*/, '-')) != '-'
|
||||||
sw.call(val) if sw
|
sw.call(val) if sw
|
||||||
rescue ParseError
|
rescue ParseError
|
||||||
raise $!.set_option(arg, has_arg)
|
raise $!.set_option(arg, arg.length > 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
# non-option argument
|
# non-option argument
|
||||||
|
|
Loading…
Reference in a new issue