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

Missing required option doesn't throw #28

Closed
wants to merge 7 commits into from

Conversation

jontodd
Copy link

@jontodd jontodd commented Dec 30, 2013

This is a proposed fix for: #22

This approach introduces a ParseResult object which allows for the collection of multiple parse errors from the user input
and then provides this back to the caller to decide what to do. E.G. send the user the to the help dialog.

This keeps the existing API and fits with the desire to keep the parsing logic agnostic to the details of the HelpOption.

The existing pattern still fails fast with an exception:

MyCommand command = SingleCommand.singleCommand(MyCommand.class).parse(args);

This fix introduces the following pattern from the caller's perspective:

ParseResult parseResult = new ParseResult();
MyCommand command = SingleCommand.singleCommand(MyCommand.class).parse(args, parseResult);
command.helpOption.runOrShowHelp(parseResult, command);

The call to runOrShowHelp will:

  • Run the command if there are no parse errors and help has not been requsted
  • Will display help if it is requested regardless of whether there are parse errors
  • Will display parse errors and help when there are parse errors

This is a proposed fix for: airlift#22

This approach introduces a ParseResult object which allows for the collection of multiple parse errors from the user input
and then provides this back to the caller to decide what to do. E.G. send the user the to the help dialog.

This keeps the existing API and fits with the desire to keep the parsing logic agnostic to the details of the HelpOption.

The existing pattern still fails fast with an exception:

```java
MyCommand command = SingleCommand.singleCommand(MyCommand.class).parse(args);
```

This fix introduces the following pattern from the caller's perspective:

```java
ParseResult parseResult = new ParseResult();
MyCommand command = SingleCommand.singleCommand(MyCommand.class).parse(args, parseResult);
command.helpOption.runOrShowHelp(parseResult, command);
```

The call to runOrShowHelp will:
* Run the command if there are no parse errors and help has not been requsted
* Will display help if it is requested regardless of whether there are parse errors
* Will display parse errors and help when there are parse errors
Removed parent pom reference and changed orgId coordinates to allow new fork in maven central
Sonatype requires it's pom be the parent to support uploads. Followed steps outlined here: https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide
This is helpful for commands to be able to show the Help text if they have a validation failure
@jontodd jontodd closed this Jan 26, 2014
@jontodd jontodd deleted the missing_required_shows_help branch January 26, 2014 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant