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

Extract missing fields to MissingParameterException #283

Closed
ghost opened this issue Feb 7, 2018 · 1 comment
Closed

Extract missing fields to MissingParameterException #283

ghost opened this issue Feb 7, 2018 · 1 comment

Comments

@ghost
Copy link

ghost commented Feb 7, 2018

Extract missing fields information from MissingParameterException in case of the exception.

Example:

public static class DefaultExceptionHandler implements IExceptionHandler {
    public List<Object> handleException(ParameterException ex, PrintStream out, Help.Ansi ansi, String... args) {
        if (ex instanceof MissingParameterException) {
            MissingParameterException missingParameterException = (MissingParameterException) ex;

            out.println("Missing parameters: " + missingParameterException.getMissingFields());
        } else if (ex instanceof UnmatchedArgumentException) {
            out.println("Unknown parameters:" + ex.getCommandLine().getUnmatchedArguments());
        } else {
            out.println(ex.getMessage());
        }

        return Collections.emptyList();
    }
}

Proposal:

Add the method getMissingFields that returns the associated missing fields.

@remkop
Copy link
Owner

remkop commented Feb 7, 2018

I like this idea.

Note that the upcoming picocli v3.0 will have a different internal model. It no longer assumes that all parameters are fields. (To support annotating methods in addition to fields.)

So instead of returning a list of java.reflection.Field objects, the new method should probably return objects from the model. Something like this:

public static class MissingParameterException extends ParameterException {
    public List<ArgSpec<?>> getMissingParameters() { ... }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant