Software /
code /
clix
Comparison
clix.lua @ 37:bb7a51aca282
clix.lua: Fix argument handling (thanks uhoreg)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 07 Jun 2010 20:19:53 +0100 |
parent | 35:37540f89d4e2 |
child | 38:eb9f706324c7 |
comparison
equal
deleted
inserted
replaced
36:0712fda16ab6 | 37:bb7a51aca282 |
---|---|
104 return 1; | 104 return 1; |
105 end | 105 end |
106 return err or 0; | 106 return err or 0; |
107 end | 107 end |
108 | 108 |
109 table.remove(arg,1); | |
110 | |
111 local opts = {}; | 109 local opts = {}; |
112 | 110 |
113 local args_handled_up_to; | 111 local command, args_handled_up_to; |
114 for i, opt in ipairs(arg) do | 112 for i, opt in ipairs(arg) do |
113 print(i, opt) | |
115 if opt:match("^%-") and opt ~= "--" then | 114 if opt:match("^%-") and opt ~= "--" then |
116 local name = opt:match("^%-%-?([^%s=]+)()") | 115 local name = opt:match("^%-%-?([^%s=]+)()") |
117 name = (short_opts[name] or name):gsub("%-+", "_"); | 116 name = (short_opts[name] or name):gsub("%-+", "_"); |
118 if name:match("^no_") then | 117 if name:match("^no_") then |
119 name = name:sub(4, -1); | 118 name = name:sub(4, -1); |
120 opts[name] = false; | 119 opts[name] = false; |
121 else | 120 else |
122 opts[name] = opt:match("=(.*)$") or true; | 121 opts[name] = opt:match("=(.*)$") or true; |
123 end | 122 end |
123 elseif not command then | |
124 command = arg[i]; | |
125 args_handled_up_to = i-1; | |
124 else | 126 else |
125 args_handled_up_to = i-1; | 127 args_handled_up_to = i-1; |
126 break; | 128 break; |
127 end | 129 end |
128 end | 130 end |
129 | 131 |
130 -- Remove all the handled args from the arg array | 132 -- Remove all the handled args from the arg array |
131 for n=(args_handled_up_to or #arg),1,-1 do | 133 for n=(args_handled_up_to or #arg),1,-1 do |
132 table.remove(arg, n); | 134 table.remove(arg, n); |
133 end | 135 end |
134 | |
135 local command = arg[1]; | |
136 | 136 |
137 local ok, m = pcall(require, "clix."..command); | 137 local ok, m = pcall(require, "clix."..command); |
138 if not ok then | 138 if not ok then |
139 local is_debug; | 139 local is_debug; |
140 for i=1,#arg do | 140 for i=1,#arg do |