iffy / nim-argparse

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

FR: Provide user-defined short-circuiting, (allows `--version`) #85

Closed ZoomRmc closed 1 year ago

ZoomRmc commented 1 year ago

A user defined error flag for short-circuiting, such as "argparse_help" would be nice, as it could allow react to a flag/command. Currently it looks like you can't ignore the absence of positional arguments and act on a flag, such as -v/--version. At the very least a hardcoded "argparse_version" is enough to get by.

iffy commented 1 year ago

Does the shortcircuit arg to flag do what you want? https://github.com/iffy/nim-argparse/blob/master/src/argparse.nim#L143

If not, can you provide an example of how you'd like it to look?

ZoomRmc commented 1 year ago

Ouch, I'm so sorry, don't know how I missed it. flag("-v", "--version", help="Print version and exit" and except ShortCircuit as err: (if err.flag == "version": echo versionConst) completely covers it.