Skip to content

Support splitting subcommands across multiple classes with the same @Command group #125

Description

@dblevins

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions