improvements to argparse

remove need to reparse table constantly, included original arg for error
message.
develop
Andriel Chaoti 2023-09-09 12:56:10 -06:00
parent d019ae81c0
commit 85cd0cd01c
No known key found for this signature in database
GPG Key ID: CF7EA34A68224617
1 changed files with 6 additions and 7 deletions

@ -196,17 +196,16 @@ function coords(arg, arg_name, skip_validation)
return pos
end
local toBool={["true"]=true,["yes"]=true,["y"]=true,["on"]=true,["1"]=true,
["false"]=false,["no"]=false,["n"]=false,["off"]=false,["0"]=false}
function boolean(arg, arg_name)
local toBool={["true"]=true,["yes"]=true,["y"]=true,["on"]=true,["1"]=true,
["false"]=false,["no"]=false,["n"]=false,["off"]=false,["0"]=false}
arg = string.lower(arg)
if toBool[arg] == nil then
local arg_lower = string.lower(arg)
if toBool[arg_lower] == nil then
arg_error(arg_name,
'unknown value: "%s"; expected "true", "yes", "false", or "no"')
'unknown value: "%s"; expected "true", "yes", "false", or "no"', arg)
end
return toBool[arg]
return toBool[arg_lower]
end
return _ENV