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

Subcommand with inherited mixed-in standard help options + HelpCommand class: failure #1319

Closed
deining opened this issue Feb 1, 2021 · 2 comments
Milestone

Comments

@deining
Copy link
Contributor

deining commented Feb 1, 2021

Minimum working example:

import picocli.CommandLine;
import picocli.CommandLine.ScopeType;
import picocli.CommandLine.*;

@Command(scope = ScopeType.INHERIT, mixinStandardHelpOptions = true, subcommands = { HelpCommand.class })
public class InheritHelpApp  {

    @Command()
    void sub(@Option(names = "-foo") int foo) {
        System.out.printf("Foo: %d", foo);
    }

    public static void main (String... args) {
        new CommandLine(new InheritHelpApp()).execute("sub", "-foo", "42" );
    }
}

When running this code, I'm getting

Exception in thread "main" picocli.CommandLine$DuplicateOptionAnnotationsException: Option name '-h' is used by both field boolean picocli.CommandLine$AutoHelpMixin.helpRequested and field boolean picocli.CommandLine$HelpCommand.helpRequested
	at picocli.CommandLine$DuplicateOptionAnnotationsException.create(CommandLine.java:17971)
	at picocli.CommandLine$DuplicateOptionAnnotationsException.access$2500(CommandLine.java:17965)
	at picocli.CommandLine$Model$CommandSpec.addOption(CommandLine.java:6574)
	at picocli.CommandLine$Model$CommandSpec.addMixin(CommandLine.java:6820)
	at picocli.CommandLine$Model$CommandSpec.mixinStandardHelpOptions(CommandLine.java:7162)
	at picocli.CommandLine$Model$CommandSpec.mixinStandardHelpOptions(CommandLine.java:7178)
	at picocli.CommandLine$Model$CommandReflection.extractCommandSpec(CommandLine.java:11409)
	at picocli.CommandLine$Model$CommandSpec.forAnnotatedObject(CommandLine.java:6204)
	at picocli.CommandLine.<init>(CommandLine.java:227)
	at picocli.CommandLine.<init>(CommandLine.java:221)
	at picocli.CommandLine.<init>(CommandLine.java:196)
	at InheritHelpApp.main(InheritHelpApp.java:14)

It's the combination of inherited scope + mixinStandardHelpOptions + subcommands = { HelpCommand.class } that's causing trouble here. If I set scope to ScopeType.LOCAL, the sample runs fine.

@remkop
Copy link
Owner

remkop commented Feb 2, 2021

Good catch!

I thought I had fixed this with #1316, but it turns out that the HelpCommand has a -h/--help option that does not use mixinStandardHelpOptions...

I may need to add special logic for HelpCommand, still thinking about how to address this.

@remkop
Copy link
Owner

remkop commented Feb 21, 2021

I finally had time to look at this.

I resolved this by not inheriting the standard help options mixin if a command already has one of the -h, --help, -V or --version options.

@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
MarkoMackic pushed a commit to MarkoMackic/picocli that referenced this issue Oct 17, 2021
…n parent has inherited mixed-in help options and the built-in `HelpCommand` subcommand.

Closes remkop#1319
MarkoMackic added a commit to MarkoMackic/picocli that referenced this issue Oct 17, 2021
…ion` when parent has inherited mixed-in help options and the built-in `HelpCommand` subcommand."

This reverts commit 1a95bf2.
MarkoMackic added a commit to MarkoMackic/picocli that referenced this issue Oct 17, 2021
MarkoMackic added a commit to MarkoMackic/picocli that referenced this issue Oct 17, 2021
…ion` when parent has inherited mixed-in help options and the built-in `HelpCommand` subcommand."

This reverts commit 1a95bf2.
MarkoMackic added a commit to MarkoMackic/picocli that referenced this issue Oct 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants