Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: no way to supply default values for options set as multiple #76

Open
d4rckh opened this issue Apr 16, 2022 · 0 comments
Open

bug: no way to supply default values for options set as multiple #76

d4rckh opened this issue Apr 16, 2022 · 0 comments

Comments

@d4rckh
Copy link

d4rckh commented Apr 16, 2022

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:

Error: type mismatch: got 'string' for '"Content-Type: application/json"' but expected 'seq[string]'

Everything works as expected if I don't supply default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant