[前][次][番号順一覧][スレッド一覧]

ruby-changes:47297

From: nobu <ko1@a...>
Date: Mon, 24 Jul 2017 10:56:10 +0900 (JST)
Subject: [ruby-changes:47297] nobu:r59412 (trunk): optparse.rb: case-sensitive candidate

nobu	2017-07-24 10:56:04 +0900 (Mon, 24 Jul 2017)

  New Revision: 59412

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59412

  Log:
    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

  Modified files:
    trunk/lib/optparse.rb
    trunk/test/optparse/test_bash_completion.rb
Index: test/optparse/test_bash_completion.rb
===================================================================
--- test/optparse/test_bash_completion.rb	(revision 59411)
+++ test/optparse/test_bash_completion.rb	(revision 59412)
@@ -40,4 +40,9 @@ class TestOptionParser::BashCompletion < https://github.com/ruby/ruby/blob/trunk/test/optparse/test_bash_completion.rb#L40
   def test_long_for_option_complete
     assert_equal(%w[hello help], @opt.candidate("--for=h"))
   end
+
+  def test_case_sensitive
+    @opt.define("-Z") {}
+    assert_equal(%w[-z], @opt.candidate("-z"))
+  end
 end
Index: lib/optparse.rb
===================================================================
--- lib/optparse.rb	(revision 59411)
+++ lib/optparse.rb	(revision 59412)
@@ -1744,16 +1744,16 @@ XXX https://github.com/ruby/ruby/blob/trunk/lib/optparse.rb#L1744
   def candidate(word)
     list = []
     case word
+    when '-'
+      long = short = true
     when /\A--/
       word, arg = word.split(/=/, 2)
       argpat = Completion.regexp(arg, false) if arg and !arg.empty?
       long = true
-    when /\A-(!-)/
-      short = true
     when /\A-/
-      long = short = true
+      short = true
     end
-    pat = Completion.regexp(word, true)
+    pat = Completion.regexp(word, long)
     visit(:each_option) do |opt|
       next unless Switch === opt
       opts = (long ? opt.long : []) + (short ? opt.short : [])

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]