Changeset

37:bb7a51aca282

clix.lua: Fix argument handling (thanks uhoreg)
author Matthew Wild <mwild1@gmail.com>
date Mon, 07 Jun 2010 20:19:53 +0100
parents 36:0712fda16ab6
children 38:eb9f706324c7
files clix.lua
diffstat 1 files changed, 8 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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;