-
Notifications
You must be signed in to change notification settings - Fork 428
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
Flag to stop parsing on first unmatched argument #215
Comments
Interesting use case. I'd like to support it. Note that picocli's parsing behaviour changed with the picocli 2.0 release to support mixing options with positional parameters on the command line. As a result, I believe the latest version of picocli now works more similar to JCommander: unmatched commands are added to the list but parsing continues and picocli tries to match options encountered after the unmatched parameter (so it may apply these options to the top-level command).
Thoughts? |
A |
I'm still thinking about a good way to handle this in a generic way. A One idea is to have some kind of callback mechanism that would enable users to plug in custom parser behaviour. Thinking out loud:
Thoughts? |
Sure, but such an API is hard to get right and boolean flags are easier for the user to understand. If you add a callback or |
I just realized that you can accomplish your use case with picocli v2 by parsing the input twice. (This should work even without a I still think that making parsing behaviour configurable will become necessary at some point in the future, but at least this allows you to make progress. What do you think?
If |
I have changed my mind on this and I am planning to support a |
Fixed in master and 2.x branch. Please verify. |
Released in 2.3.0 |
I have a command line utility that discovers subcommands dynamically, based on the parameters given to the main command. In other words: I only know the list of available subcommands after parsing some of the command line parameters and doing some work, e.g. extending and then scanning the classpath.
Something like this:
usage: cmd [--plugin-directory=PATH] <plugin-name> [plugin options]
. Plugins are discovered dynamically based on the value of the--plugin-directory
parameter.This works (somehow) with picocli because it stops as soon as it finds an unknown parameter. This is exactly the behavior I need.
Currently I parse the command line in two steps: First I build a parser with
setUnmatchedArgumentsAllowed(true)
and parse everything up to the first unknown parameter. Then, I load config files, extend the classpath, discover all plugins and build a second parser. This time I can add all plugins and let picocli do its job.With JCommander for example I cannot do this, because it would find plug-in parameters that have the same name as a main parameter and mix them together, regardless of their position, during the first parsing step.
I have some questions:
The text was updated successfully, but these errors were encountered: