add seq separator support

This commit is contained in:
Daylin Morgan 2024-11-18 13:58:44 -06:00
parent 938131c6cd
commit 748f7e1bd6
Signed by: daylin
GPG key ID: 950D13E9719334AD

View file

@ -741,11 +741,23 @@ proc parse*(p: OptParser, target: var float) =
"failed to parse value for [b]" & p.key & "[/] as float: [b]" & p.val "failed to parse value for [b]" & p.key & "[/] as float: [b]" & p.val
) )
proc parse*[T](p: OptParser, target: var seq[T]) = proc parse*[T](p: var OptParser, target: var seq[T]) =
checkVal p checkVal p
case p.sep
of ",=":
let baseVal = p.val
for v in baseVal.split(","):
p.val = v.strip()
if p.val == "": continue
var parsed: T var parsed: T
parse(p, parsed) parse(p, parsed)
target.add parsed target.add parsed
of "=", "":
var parsed: T
parse(p, parsed)
target.add parsed
else: assert false
proc parse*(p: OptParser, target: var Count) = proc parse*(p: OptParser, target: var Count) =
# if value set to that otherwise increment # if value set to that otherwise increment