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

Update README.md #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,15 @@ The creation of the `--help` option can be disabled by passing `null` as the
constructing a `HelpFormatter` instance. In the above example a
`DefaultHelpFormatter` was created with the prologue and epilogue.

For correct show help message you must add handler for help exception:
```
val parser = try {
ArgParser(args).parseInfo(::YourParser)
} catch (e: ShowHelpException) {
e.printAndExit()
}
```

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing that this was not clear enough!

The supported way to do this is actually to use mainBody, or at least to catch all SystemExitExceptions, as mentioned in the Error Handling section.

Perhaps just change this to say something like:

For help messages to correctly display you must properly handle any SystemExitException that is thrown as described in Error Handling.

You could even link to that section.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your response.

I think, that catch only awaited exception (such as ShowHelpException) is best way. In this case we need to catch only exception which will say to show help and catching ShowHelpException will give us all what we need.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I understand your point.

ShowHelpException is a subclass of SystemExitException. In most cases you probably want to handle all SystemExitExceptions, not just ShowHelpException. They all contain a message for the user, as well as an exit code. The exit code for ShowHelpException just happens to be 0.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean that any other exception must be handled by other way. In this case we need to catch just ShowHelpException and it is will be ok for show help message

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you don't need to handle other SystemExitExceptions in a different way. All SystemExitExceptions can be handled by calling their printAndExit() method or by using mainBody (which will call printAndExit for you). It would be pretty unusual to need to catch only ShowHelpException.


## Caveats

Expand Down