clix.lua: Fix argument handling (thanks uhoreg)

Mon, 07 Jun 2010 20:19:53 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Mon, 07 Jun 2010 20:19:53 +0100
changeset 37
bb7a51aca282
parent 36
0712fda16ab6
child 38
eb9f706324c7

clix.lua: Fix argument handling (thanks uhoreg)

clix.lua file | annotate | diff | comparison | revisions
--- a/clix.lua	Mon Jun 07 13:42:46 2010 -0400
+++ b/clix.lua	Mon Jun 07 20:19:53 2010 +0100
@@ -106,12 +106,11 @@
 	return err or 0;
 end
 
-table.remove(arg,1);
-
 local opts = {};
 
-local args_handled_up_to;
+local command, args_handled_up_to;
 for i, opt in ipairs(arg) do
+        print(i, opt)
         if opt:match("^%-") and opt ~= "--" then
                 local name = opt:match("^%-%-?([^%s=]+)()")
                 name = (short_opts[name] or name):gsub("%-+", "_");
@@ -121,10 +120,13 @@
                 else
                         opts[name] = opt:match("=(.*)$") or true;
                 end
+        elseif not command then
+        	command = arg[i];
+       		args_handled_up_to = i-1;
         else
-        	args_handled_up_to = i-1;
-		break;
-        end
+       		args_handled_up_to = i-1;
+       		break;
+       	end
 end
 
 -- Remove all the handled args from the arg array
@@ -132,8 +134,6 @@
 	table.remove(arg, n);
 end
 
-local command = arg[1];
-
 local ok, m = pcall(require, "clix."..command);
 if not ok then
 	local is_debug;

mercurial