murarth / gumdrop

Rust option parser with custom derive support

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`parse_args_or_exit` function

tailhook opened this issue · comments

It would be nice to have a single function which does the following:

  1. Checks arguments
  2. Prints help if --help is specified
  3. Exits with 0 if help is specified or error code 2 if there is an error

I think this is important because even if front page examples there there are few mistakes: (1) no error code returned, (2) error message is printed to stdout not stderr.

What do you think? Is there any limitations of help that could be generated by such function? I.e. a problem with subcommands or something?

I think this can probably be done with just a small internal change and one added method to the Options trait. I'm working on the implementation now.

As for the main docs (and examples), I'll correct those. I don't believe eprintln! existed when I wrote them. However, I have no excuse for using return instead of exit. Just laziness.

@tailhook: I've just pushed the implementation for parse_args_or_exit (and parse_args_default_or_exit). Let me know what you think.

@murarth works fine for me. Thanks!