Software /
code /
clix
Comparison
clix.lua @ 131:58d485001448
clix: Use tabs for indentation in command line parsing
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 14 Nov 2020 15:26:06 +0100 |
parent | 127:6a27edf256c3 |
child | 165:e4391832be1e |
comparison
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); |