summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-12-05 10:39:58 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-12-05 10:39:58 +0000
commitaf3da7d124e67a195e761d2b8e82f80320f57387 (patch)
tree43932329cfd3263545639cc67fe8cf6b0f21d113
parent174052749c836c59dcdb13a38c181bb3374b66e6 (diff)
* lib/optparse.rb (OptionParser::Completion#complete): new parameter
to direct case insensitiveness. * lib/optparse.rb (OptionParser#order!): ignore case only for long option. [ruby-dev:25048] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7464 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog10
-rw-r--r--lib/optparse.rb29
-rw-r--r--test/optparse/test_noarg.rb4
3 files changed, 23 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index 1cabc75011..0e106b8458 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Sun Dec 5 19:39:17 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * lib/optparse.rb (OptionParser::Completion#complete): new parameter
+ to direct case insensitiveness.
+
+ * lib/optparse.rb (OptionParser#order!): ignore case only for long
+ option. [ruby-dev:25048]
+
Sun Dec 5 00:54:32 2004 WATANABE Hirofumi <eban@ruby-lang.org>
* mkconfig.rb: setup library paths before requiring library.
@@ -36,7 +44,7 @@ Sat Dec 4 14:28:56 2004 Dave Thomas <dave@pragprog.com>
# :section: Dave's Section
# comment material
# -----------
- The lines before :section: are removed, and identical lines at the end are
+ The lines before :section: are removed, and identical lines at the end are
also removed if present.
Fri Dec 3 12:25:21 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
diff --git a/lib/optparse.rb b/lib/optparse.rb
index 01facfe02d..79dde295cf 100644
--- a/lib/optparse.rb
+++ b/lib/optparse.rb
@@ -207,9 +207,9 @@ class OptionParser
# and resolved against a list of acceptable values.
#
module Completion
- def complete(key, pat = nil)
+ def complete(key, icase = false, pat = nil)
pat ||= Regexp.new('\A' + Regexp.quote(key).gsub(/\w+\b/, '\&\w*'),
- ignore_case?)
+ icase)
canon, sw, k, v, cn = nil
candidates = []
each do |k, *v|
@@ -250,10 +250,6 @@ class OptionParser
def convert(opt = nil, val = nil, *)
val
end
-
- def ignore_case?
- false
- end
end
@@ -263,11 +259,6 @@ class OptionParser
class OptionMap < Hash
include Completion
end
- class OptionCaseMap < OptionMap
- def ignore_case?
- true
- end
- end
#
@@ -523,7 +514,7 @@ class OptionParser
def initialize
@atype = {}
@short = OptionMap.new
- @long = OptionCaseMap.new
+ @long = OptionMap.new
@list = []
end
@@ -632,13 +623,15 @@ class OptionParser
# searching list.
# : ((|opt|))
# searching key.
+ # : ((|icase|))
+ # search case insensitive if true.
# : ((|*pat|))
# optional pattern for completion.
# : (({block}))
# yielded with the found value when succeeded.
#
- def complete(id, opt, *pat, &block)
- __send__(id).complete(opt, *pat, &block)
+ def complete(id, opt, icase = false, *pat, &block)
+ __send__(id).complete(opt, icase, *pat, &block)
end
#
@@ -1277,7 +1270,7 @@ class OptionParser
when /\A--([^=]*)(?:=(.*))?/
opt, rest = $1, $2
begin
- sw, = complete(:long, opt)
+ sw, = complete(:long, opt, true)
rescue ParseError
raise $!.set_option(arg, true)
end
@@ -1431,17 +1424,19 @@ class OptionParser
searching table.
: ((|opt|))
searching key.
+ : ((|icase|))
+ search case insensitive if true.
: ((|*pat|))
optional pattern for completion.
: (({block}))
yielded with the found value when succeeded.
=end #'#"#`#
- def complete(typ, opt, *pat)
+ def complete(typ, opt, icase = false, *pat)
if pat.empty?
search(typ, opt) {|sw| return [sw, opt]} # exact match or...
end
raise AmbiguousOption, catch(:ambiguous) {
- visit(:complete, typ, opt, *pat) {|opt, *sw| return sw}
+ visit(:complete, typ, opt, icase, *pat) {|opt, *sw| return sw}
raise InvalidOption, opt
}
end
diff --git a/test/optparse/test_noarg.rb b/test/optparse/test_noarg.rb
index cd57ed5a56..28c469093d 100644
--- a/test/optparse/test_noarg.rb
+++ b/test/optparse/test_noarg.rb
@@ -31,8 +31,8 @@ module TestOptionParser::NoArg
assert_equal(%w"", no_error {@opt.parse!(%w"-o")})
assert_equal(true, @flag)
@flag = nil
- no_error {@opt.parse!(%w"-O")}
- assert_equal(true, @flag)
+ assert_raises(OptionParser::InvalidOption) {@opt.parse!(%w"-O")}
+ assert_nil(@flag)
@flag = nil
assert_equal(%w"foo", no_error {@opt.parse!(%w"-o foo")})
assert_equal(true, @flag)