iffy / nim-argparse

Argument parsing for Nim
MIT License
120 stars 8 forks source link

`required=true` causes an error if the option is set using an environment variable #67

Closed Schnouki closed 2 years ago

Schnouki commented 3 years ago

Hey there,

Recently started using argparse. Works great so far, but I have a small issue: I have an option defined as this:

let p = newParser:
  command("run"):
    option("--token", help="App token", env="APP_TOKEN", required=true)
    run:
      discard

try:
  p.run()
except UsageError as e:
  stderr.writeLine getCurrentExceptionMsg()
  quit(1)

If I set APP_TOKEN to some non-empty value, I expect my program to run. But instead I'm getting an error: "Option --fbx-token is required and was not provided".

Would it be possible to fix that?

Thanks a lot! 🙂

iffy commented 3 years ago

Yes, I think logically it makes sense to change it to behave like you've described. I'm not sure when I'll get around to it, but I'll take a look when I can.