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

Another subcommand named 'help' already exists for command '<main class>' #716

Closed
Mikusch opened this issue Jun 4, 2019 · 3 comments
Closed
Labels
theme: parser An issue or change related to the parser type: bug 🐛
Milestone

Comments

@Mikusch
Copy link

Mikusch commented Jun 4, 2019

Hi there,

I keep running into the following exception
picocli.CommandLine$InitializationException: Another subcommand named 'help' already exists for command '<main class>'

I know what the cause of this is but I don't know how to fix it.

I have an abstract class AbstractCommand which is annotated so that every class extending it automatically has a specified (custom) help command:

@CommandLine.Command(subcommands = HelpCommand.class)
public abstract class AbstractCommand {
    ...
}

All my commands are extending this abstract class and this hasn't caused any issues thus far.

The problem arises when I make another abstract class extending AbstractCommand e.g.

public abstract class Subcommand extends AbstractCommand {
    ...
}

Now, when I call CommandSpec.forAnnotatedObject(MyCommand.class, factory), where MyCommand extends Subcommand, it will throw an exception telling me that it already has a help command. I couldn't find the exact cause for the issue in the picocli source code but I can only assume that it is trying to add the help command twice due to Subcommand inheriting the annotation on AbstractCommand.

I would like to add that this only occurs on version 4.0.0-alpha-2 and up, worked just fine before that.

Perhaps it is related to this?

@remkop
Copy link
Owner

remkop commented Jun 4, 2019

I think it’s caused by this change: #660

@remkop
Copy link
Owner

remkop commented Jun 4, 2019

May need to revert that.

@remkop
Copy link
Owner

remkop commented Jun 6, 2019

This change has been included in the 4.0.0-beta-1b release that just came out.
I added a test but it would be good if you can confirm the problem no longer exists.

@remkop remkop added the theme: parser An issue or change related to the parser label Apr 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: parser An issue or change related to the parser type: bug 🐛
Projects
None yet
Development

No branches or pull requests

2 participants