opts: handling for packed short options
authorAlexandre Pennetier <alexandre.pennetier@me.com>
Mon, 11 Jun 2012 21:01:26 +0000 (17:01 -0400)
committerJean Privat <jean@pryen.org>
Fri, 21 Sep 2012 19:16:07 +0000 (15:16 -0400)
Signed-off-by: Alexandre Pennetier <alexandre.pennetier@me.com>

lib/opts.nit

index 11c2ccc..06fe44e 100644 (file)
@@ -261,21 +261,37 @@ class OptionContext
                var parseargs = true
                build
                var rest = _rest
-               
+
                while parseargs and it.is_ok do
                        var str = it.item
                        if str == "--" then
-                               it.next
                                rest.add_all(it.to_a)
                                parseargs = false
                        else
-                               if _optmap.has_key(str) then
-                                       var opt = _optmap[str]
-                                       it.next
-                                       opt.read_param(it)
+                               # We're looking for packed short options
+                               if str.last_index_of('-') == 0 and str.length > 2 then
+                                       var next_called = false
+                                       for i in [1..str.length] do
+                                               var short_opt = "-" + str[i].to_s
+                                               if _optmap.has_key(short_opt) then
+                                                       var option = _optmap[short_opt]
+                                                       if option isa OptionParameter then
+                                                               it.next
+                                                               next_called = true
+                                                       end
+                                                       option.read_param(it)
+                                               end
+                                       end
+                                       if not next_called then it.next
                                else
-                                       rest.add(it.item)
-                                       it.next
+                                       if _optmap.has_key(str) then
+                                               var opt = _optmap[str]
+                                               it.next
+                                               opt.read_param(it)
+                                       else
+                                               rest.add(it.item)
+                                               it.next
+                                       end
                                end
                        end
                end