picocli
picocli copied to clipboard
Subcommand overrides option value set in parent command with default value
Hi. We are currently not using inherited options and because we are using Picocli through Quarkus we are sharing options between command and subcommands by making them a @Singleton
(which should be equivalent to having them on a static field but then they can be injected).So we have something like this:
@Singleton
public class MyOption {
@Option(names = "-m", defaultValue = "default", description = "My option")
String my;
}
then both the parent and the subcommand have the following:
@Mixin
@Inject
MyOption myOption;
When sub command is called with the option specified in the parent, the option value is overwritten with the default:
command -m bla subcommand # Value of MyOption.my is 'default' instead of `bla`
I don't know if this affects inherited options or other ways of sharing (e.g. static fields), but I guess in this case Picocli is only checking if the options are defined on the children before setting the default value. Could Picocli also check if the value is already set and if it is don't set the default value?