Skip to content

Dynamic completion shows wrong descriptions for group command children with duplicate names #448

@stalep

Description

@stalep

Summary

When multiple group commands have child subcommands with the same name (e.g. add, list, remove), the dynamic completion (--aesh-complete) returns the correct subcommand names but wrong descriptions. The descriptions appear to come from whichever command was last registered with that name, rather than from the specific group's child.

Reproduction

Given a CLI with multiple group commands sharing child names:

jbang alias add    -> "Add alias for script reference."
jbang catalog add  -> "Add a catalog."
jbang template add -> "Add template for script reference."
jbang deps add     -> "Add dependencies to a jbang file."
jbang trust add    -> "Add trust domains."

Completion output:

$ jbang --aesh-complete -- "alias "
add     Add dependencies to a jbang file.    # WRONG - should be "Add alias for script reference."
list    List active configuration values     # WRONG - should be "Lists locally defined aliases..."
remove  Remove trust domains.                # WRONG - should be "Remove existing alias."

$ jbang --aesh-complete -- "catalog "
add     Add dependencies to a jbang file.    # WRONG
list    List active configuration values     # WRONG
remove  Remove trust domains.                # WRONG

$ jbang --aesh-complete -- "config "
get     Get a configuration value            # correct
set     Set a configuration value            # correct
list    Lists installed commands.             # WRONG - should be "List active configuration values"

Note that config get, config set, config unset show correct descriptions because those names are unique across all group commands.

Expected behavior

Each group command's completion should show the descriptions from its own children, not from a shared/global lookup.

Root cause

The performDynamicCompletion() method likely looks up subcommand descriptions by name from a flat map or the last-registered command, rather than scoping the lookup to the specific group command being completed.

Context

Found in jbang (jbangdev/jbang#2453) where alias, template, catalog, trust, deps, and config all have add/list/remove subcommands.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions