Skip to content

feat: Add HasSubcommands() so menus don't require discovery - #63

Open
boblail wants to merge 1 commit into
mainfrom
lail/has-subcommands
Open

feat: Add HasSubcommands() so menus don't require discovery#63
boblail wants to merge 1 commit into
mainfrom
lail/has-subcommands

Conversation

@boblail

@boblail boblail commented Aug 19, 2026

Copy link
Copy Markdown
Member

Rendering a menu called Subcommands() on every child twice — once in Expand() (even at depth 0, where the result was discarded) and once to decide whether to render the : sigil — and both calls can trigger discovery, which may exec the child.

Expand() now returns immediately at depth 0, and the sigil is rendered with the new HasSubcommands() predicate, which answers "may this command have subcommands?" without performing discovery. The sigil accordingly now means "may have subcommands": an empty module keeps its : at depth 0. Commands built by external contracts can opt in via the SubcommandsReporter interface; otherwise HasSubcommands() falls back to calling Subcommands(), preserving today's behaviour.

Groundwork for progressive OpenCLI discovery (#62).

🤖 Generated with Claude Code

Rendering a menu called Subcommands() on every child twice — once in
Expand() (even at depth 0, where the result was discarded) and once to
decide whether to render the ':' sigil. Both calls can trigger discovery,
which may exec the child.

Expand() now returns immediately at depth 0, and the sigil is rendered
with the new HasSubcommands() predicate, which answers "may this command
have subcommands?" without performing discovery. Commands built by
external contracts can opt in via the SubcommandsReporter interface;
otherwise HasSubcommands() falls back to calling Subcommands().

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@boblail boblail left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread commands.go
return parallelMap(c, func(cmd Command) ([]Command, []error) {
// At depth 0, nothing is expanded; don't ask for subcommands at all
// because Subcommands() may trigger discovery.
if depth == 0 {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimization: check this before calling cmd.Subcommands() 👍

@boblail
boblail marked this pull request as ready for review August 19, 2026 00:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant