iffy / nim-argparse

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

Treatment of `--help` is a bit confusing #44

Closed rrthomas closed 3 years ago

rrthomas commented 3 years ago

It is not obvious that the built-in implementation of --help does not exit the program, so this is up to the author. This is actually quite useful, as it makes it easy to add extra material after the auto-generated output.

Also, it is not obvious that if you use nohelpflag() and then define a --help flag anyway, it will reactivate the built-in output. It seems not to be possible to override the built-in output altogether.

iffy commented 3 years ago

It is not obvious that the built-in implementation of --help does not exit the program, so this is up to the author. This is actually quite useful, as it makes it easy to add extra material after the auto-generated output.

When I use run() passing --help does exit the program.

import argparse
var p = newParser("test"):
  flag("-a", "--apple")
p.run()
echo "after run"

Compiling and running that with --help, I never see "after run":

$ ./f --help
test

Usage:
  test [options] 

Options:
  -a, --apple
  -h, --help                 Show this help

You're correct that p.parse() does not exit the program though.

Also, it is not obvious that if you use nohelpflag() and then define a --help flag anyway, it will reactivate the built-in output. It seems not to be possible to override the built-in output altogether.

Yep, that's a bug! I've filed this: https://github.com/iffy/nim-argparse/issues/46

rrthomas commented 3 years ago

Indeed, I did not specify that I was talking about parse vs run. Coming from Python argparse, and similar getopt-related packages, e.g. gengetopt, which only have the equivalent of parse, and where the autogenerated --help code does exit, I was perhaps understandably confused!

iffy commented 3 years ago

Is it more obvious with the new README updates? https://github.com/iffy/nim-argparse#parse If not, please reopen. Thank you!

rrthomas commented 3 years ago

Thanks, that helps!