Skip to content

Allow a node with a Run() method to run without a subcommand#614

Merged
alecthomas merged 1 commit into
alecthomas:masterfrom
NoahStarkenburg:runnable-parent-command
Jul 5, 2026
Merged

Allow a node with a Run() method to run without a subcommand#614
alecthomas merged 1 commit into
alecthomas:masterfrom
NoahStarkenburg:runnable-parent-command

Conversation

@NoahStarkenburg

Copy link
Copy Markdown
Contributor

Fixes #561

A node that declares subcommands but also defines a Run() method cannot currently be invoked on its own. Running the app with no subcommand fails with expected one of ..., even though Run() is defined.

This matches the approach suggested in the issue: if a node has a Run() method it can act as a terminating command. checkMissingChildren no longer requires one of the subcommands to be selected when the node is runnable. ctx.Run() already runs such a node (the application node with a Run() method), so no change was needed there.

Subcommands still work, and nodes without a Run() method still require a subcommand. Added tests for all three cases.

A node that declares subcommands but also defines a Run() method can now
be invoked on its own. checkMissingChildren no longer requires one of the
subcommands to be selected when the node is runnable, and ctx.Run()
already runs such a node.

@alecthomas alecthomas left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Awesome, thanks!

@alecthomas alecthomas merged commit 9d8d9f7 into alecthomas:master Jul 5, 2026
5 checks passed
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.

Allow Root commands when there are subcommands

2 participants