Open d4rckh opened 2 years ago
there's a bug in argparse which won't let me supply default values for an option that i set as multiple. here's a small poc which will error:
import argparse var p = newParser: option("-H", "--header", default=some(@["Content-Type: application/json"]), help="specify headers", multiple=true) try: let parsedArgs = p.parse(commandLineParams()) echo parsedArgs.header except UsageError as e: stderr.writeLine getCurrentExceptionMsg() quit(1)
Error: type mismatch: got <string, string, default: Option[seq[string]], help: string, multiple: bool> but expected one of: proc option(name1: string; name2 = ""; help = ""; default = none[string](); env = ""; multiple = false; choices: seq[string] = @[]; required = false; hidden = false) first type mismatch at position: 3 required type for default: Option[system.string] but expression 'default = some(@["Content-Type: application/json"])' is of type: Option[seq[string]] proc option[T](val: sink T): Option[T] first type mismatch at position: 2 extra argument given expression: option("-H", "--header", default = some(@["Content-Type: application/json"]),
If I change default to default=some("Content-Type: application/json"), the error will change:
default=some("Content-Type: application/json")
Error: type mismatch: got 'string' for '"Content-Type: application/json"' but expected 'seq[string]'
Everything works as expected if I don't supply default
there's a bug in argparse which won't let me supply default values for an option that i set as multiple. here's a small poc which will error:
If I change default to
default=some("Content-Type: application/json")
, the error will change:Everything works as expected if I don't supply default