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

DuplicateOptionAnnotationsException thrown on mixinStandardHelpOptions by picocli-codegen #1316

Closed
charphi opened this issue Jan 28, 2021 · 5 comments
Labels
theme: codegen An issue or change related to the picocli-codegen module type: bug 🐛
Milestone

Comments

@charphi
Copy link
Contributor

charphi commented Jan 28, 2021

DuplicateOptionAnnotationsException is thrown by picocli-codegen when mixinStandardHelpOptions is set to true on both a command with scope INHERIT and a subcommand.

Example:

@CommandLine.Command(
        name = "example",
        mixinStandardHelpOptions = true,
        scope = CommandLine.ScopeType.INHERIT,
        subcommands = AutoComplete.GenerateCompletion.class
)
public class Example {
}

Stacktrace:

[ERROR] FATAL ERROR: picocli.CommandLine$DuplicateOptionAnnotationsException: Option name '-h' is used by both field boolean picocli.CommandLine$AutoHelpMixin.helpRequested and field boolean picocli.CommandLine$AutoHelpMixin.helpRequested
        at picocli.CommandLine$DuplicateOptionAnnotationsException.create(CommandLine.java:17963)
        at picocli.CommandLine$DuplicateOptionAnnotationsException.access$2500(CommandLine.java:17957)
        at picocli.CommandLine$Model$CommandSpec.addOption(CommandLine.java:6572)
        at picocli.CommandLine$Model$CommandSpec.addMixin(CommandLine.java:6818)
        at picocli.CommandLine$Model$CommandSpec.mixinStandardHelpOptions(CommandLine.java:7157)
        at picocli.CommandLine$Model$CommandSpec.mixinStandardHelpOptions(CommandLine.java:7172)
        at picocli.CommandLine$Model$CommandSpec.mixinStandardHelpOptions(CommandLine.java:7172)
        at picocli.codegen.annotation.processing.AbstractCommandSpecProcessor$Context.connectModel(AbstractCommandSpecProcessor.java:922)
        at picocli.codegen.annotation.processing.AbstractCommandSpecProcessor$Context.access$000(AbstractCommandSpecProcessor.java:807)
        at picocli.codegen.annotation.processing.AbstractCommandSpecProcessor.tryProcess(AbstractCommandSpecProcessor.java:194)
        at picocli.codegen.annotation.processing.AbstractCommandSpecProcessor.process(AbstractCommandSpecProcessor.java:165)
@remkop
Copy link
Owner

remkop commented Jan 29, 2021

Hi @charphi , this is by design:

putting scope=INHERIT on a command means that you don't need to put mixinStandardHelpOptions = true on any subcommands any more.

This is documented in the user manual: https://picocli.info/#_inherited_command_attributes

Other options are not inherited.

@remkop
Copy link
Owner

remkop commented Jan 29, 2021

Oh, I see what you mean now; since GenerateCompletion is a built-in command, people may expect to be able to combine it with scope = INHERIT.

Perhaps we should add a WARN admonition to the Inherited Command Attributes section that this is a known limitation.

@remkop
Copy link
Owner

remkop commented Jan 29, 2021

Ah wait, I think I understand what you mean (this time for real 🤣 - at least I hope...)

There is an inconsistency: at runtime, the above Example class does not throw a DuplicateOptionAnnotationsException; it has some special logic to prevent this error.
However, this special logic is missing from the annotation processor, so at compile time, when the annotation processor is enabled, we are seeing this error.

So, we should fix the annotation processor to not fail on the above Example class.

@remkop remkop added type: bug 🐛 theme: codegen An issue or change related to the picocli-codegen module labels Jan 29, 2021
@remkop remkop added this to the 4.7 milestone Jan 29, 2021
@remkop remkop closed this as completed in 148d4e3 Feb 1, 2021
@remkop
Copy link
Owner

remkop commented Feb 1, 2021

I pushed a fix to master. Please verify when you have a chance.

Thinking to release 4.6.2 soon, that includes this fix.

@charphi
Copy link
Contributor Author

charphi commented Feb 1, 2021

I've just tested and it works. Thanks!

@remkop remkop modified the milestones: 4.7, 4.6.2 Feb 23, 2021
MarkoMackic pushed a commit to MarkoMackic/picocli that referenced this issue Oct 17, 2021
…own on `mixinStandardHelpOptions` for subcommands when parent has `scope = INHERIT` by `picocli-codegen` annotation processor.

Closes remkop#1316
MarkoMackic added a commit to MarkoMackic/picocli that referenced this issue Oct 17, 2021
…ion` thrown on `mixinStandardHelpOptions` for subcommands when parent has `scope = INHERIT` by `picocli-codegen` annotation processor."

This reverts commit 735f951.
MarkoMackic added a commit to MarkoMackic/picocli that referenced this issue Oct 17, 2021
…ion` thrown on `mixinStandardHelpOptions` for subcommands when parent has `scope = INHERIT` by `picocli-codegen` annotation processor."

This reverts commit 735f951.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: codegen An issue or change related to the picocli-codegen module type: bug 🐛
Projects
None yet
Development

No branches or pull requests

2 participants