From 85cd0cd01cffd37472d56e5119e76370109b221d Mon Sep 17 00:00:00 2001 From: Andriel Chaoti <3628387+AndrielChaoti@users.noreply.github.com> Date: Sat, 9 Sep 2023 12:56:10 -0600 Subject: [PATCH] improvements to argparse remove need to reparse table constantly, included original arg for error message. --- library/lua/argparse.lua | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/library/lua/argparse.lua b/library/lua/argparse.lua index 8da11cb28..0a652f428 100644 --- a/library/lua/argparse.lua +++ b/library/lua/argparse.lua @@ -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