add `boolean` function for argparse

implements a test for boolean values into the argparse utility that
checks for truthy style values and converts them to a lua boolean.
develop
Andriel Chaoti 2023-09-06 16:42:05 -06:00
parent ce2f35a2f1
commit 5611cdd999
No known key found for this signature in database
GPG Key ID: CF7EA34A68224617
1 changed files with 13 additions and 0 deletions

@ -196,4 +196,17 @@ function coords(arg, arg_name, skip_validation)
return pos
end
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
arg_error(arg_name,
'unknown value: "%s"; expected "true", "yes", "false", or "no"')
end
return toBool[arg]
end
return _ENV