-
Notifications
You must be signed in to change notification settings - Fork 422
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
Options in subcommands are not reset to their initial value #990
Labels
Milestone
Comments
remkop
added a commit
that referenced
this issue
Apr 19, 2020
Fixed in master. To verify, check out picocli master locally, and build it with
You can then try this in a project that uses the |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When a single
CommandLine
instance is reused multiple times, picocli is supposed to reset the values of all options and positional parameters to their initial value, and then to their default value (if a default value was defined in the annotations).Scope
With picocli 4.2.0, subcommand options are not cleared between invocations. This impacts applications that reuse a
CommandLine
instance in multiple invocations. If an option was specified in the first invocation and omitted in the second invocation, it will incorrectly retain the value from the first invocation.The problem does not manifest when a subcommand is invoked only once in a JVM process. Also, applications that do not reuse a
CommandLine
instance, and applications without subcommands, are not impacted.The problem was introduced in version 4.2.0 and does not exist in picocli 4.1.4 and earlier.
Workaround
This regression does not apply to options that have a
defaultValue
defined in the annotation: options defined as@Option(... defaultValue="...")
will correctly be reset to the default value in between multiple invocations. Use the defaultValue annotation where possible.Cause
The cause is related to recent changes for lazy subcommand instantiation and repeatable subcommands.
I may be possible to fix this by implementing this idea:
#961 (similar to #962)
The text was updated successfully, but these errors were encountered: