Summary
When two classes share the same @Command group name, only the last class registered is accessible. The earlier class's subcommands are silently overwritten.
For example, given:
@Command("auth")
public class LoginCommand {
@Command("login")
public void login(final String name) {}
}
@Command("auth")
public class RefreshCommand {
@Command("refresh")
public void refresh(final String name) {}
}
Currently auth refresh Foo works but auth login Foo fails with "No such sub-command: login" because RefreshCommand overwrites LoginCommand in the command map.
Expected Behavior
Both auth login Foo and auth refresh Foo should work. When multiple classes share the same @Command group name, their subcommands should be merged into a single CmdGroup.
This should also support overloaded subcommands across classes — two classes defining the same subcommand name with different signatures should merge into an OverloadedCmdMethod.
Implementation
The fix involves two changes:
CmdGroup — Add a merge(CmdGroup) method that combines subcommands from another group, handling all combinations of CmdMethod and OverloadedCmdMethod
Main.processClass() — When inserting a CmdGroup, check if one already exists with the same name and merge instead of overwriting
Summary
When two classes share the same
@Commandgroup name, only the last class registered is accessible. The earlier class's subcommands are silently overwritten.For example, given:
Currently
auth refresh Fooworks butauth login Foofails with "No such sub-command: login" becauseRefreshCommandoverwritesLoginCommandin the command map.Expected Behavior
Both
auth login Fooandauth refresh Fooshould work. When multiple classes share the same@Commandgroup name, their subcommands should be merged into a singleCmdGroup.This should also support overloaded subcommands across classes — two classes defining the same subcommand name with different signatures should merge into an
OverloadedCmdMethod.Implementation
The fix involves two changes:
CmdGroup— Add amerge(CmdGroup)method that combines subcommands from another group, handling all combinations ofCmdMethodandOverloadedCmdMethodMain.processClass()— When inserting aCmdGroup, check if one already exists with the same name and merge instead of overwriting