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

Dynamic and/or hidden parameters? #33

Open
DrDaleks opened this issue Apr 15, 2023 · 2 comments
Open

Dynamic and/or hidden parameters? #33

DrDaleks opened this issue Apr 15, 2023 · 2 comments

Comments

@DrDaleks
Copy link

I have a use case where I'd like to add/remove an option based on the presence/absence of a module on the classpath. I'm assuming this is impossible to do this at compile-time, but alternatively, hiding an option from the usage printout should be possible at runtime.

One way I imagined this could be possible by calling StandardErrorHandler's printUsageDocumentation using a different CommandModel with fewer elements, but cloning or modifying the command model is currently not possible afaik.

@h908714124
Copy link
Collaborator

Thanks for pointing this out. I've added a new method CommandModel.toBuilder() in 5.15.

@h908714124
Copy link
Collaborator

h908714124 commented Apr 15, 2023

I hope something like this will work:

parser.parse(List.of(args)).ifLeftOrElse(parsingFailed -> {
    CommandModel model = parsingFailed.commandModel();
    List<Option> options = model.options().stream().filter(this::isInClasspath).toList();
    StandardErrorHandler.builder().build().printUsageDocumentation(model.toBuilder().withOptions(options).build());
}, this::runCommand);

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

No branches or pull requests

2 participants