clix.lua

changeset 131
58d485001448
parent 127
6a27edf256c3
child 165
e4391832be1e
equal deleted inserted replaced
130:11d526d74460 131:58d485001448
141 141
142 local opts = {}; 142 local opts = {};
143 143
144 local command, args_handled_up_to; 144 local command, args_handled_up_to;
145 for i, opt in ipairs(arg) do 145 for i, opt in ipairs(arg) do
146 if opt:match("^%-") and opt ~= "--" then 146 if opt:match("^%-") and opt ~= "--" then
147 local name = opt:match("^%-%-?([^%s=]+)()") 147 local name = opt:match("^%-%-?([^%s=]+)()")
148 name = (short_opts[name] or name):gsub("%-+", "_"); 148 name = (short_opts[name] or name):gsub("%-+", "_");
149 if name:match("^no_") then 149 if name:match("^no_") then
150 name = name:sub(4, -1); 150 name = name:sub(4, -1);
151 opts[name] = false; 151 opts[name] = false;
152 else 152 else
153 opts[name] = opt:match("=(.*)$") or true; 153 opts[name] = opt:match("=(.*)$") or true;
154 end 154 end
155 elseif not command then 155 elseif not command then
156 command = arg[i]; 156 command = arg[i];
157 args_handled_up_to = i-1; 157 args_handled_up_to = i-1;
158 else 158 else
159 args_handled_up_to = i-1; 159 args_handled_up_to = i-1;
160 break; 160 break;
161 end 161 end
162 end 162 end
163 163
164 -- Remove all the handled args from the arg array 164 -- Remove all the handled args from the arg array
165 for n=((args_handled_up_to > 0) and args_handled_up_to or #arg),1,-1 do 165 for n=((args_handled_up_to > 0) and args_handled_up_to or #arg),1,-1 do
166 table.remove(arg, n); 166 table.remove(arg, n);

mercurial