Skip to content

feat(command): Support completion with external subcommands - #159

Merged
christerswahn merged 5 commits into
mainfrom
new-better-command
Nov 25, 2026
Merged

christerswahn merged 5 commits into
mainfrom
new-better-command

Conversation

@christerswahn

@christerswahn christerswahn commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

When command subcommand runs a separate executable "subcommand", defer the completion of the rest of the command line to that executable.

Summary by CodeRabbit

  • New Features
    • Commands can now forward all arguments after the command unchanged to another program, including option-like arguments and --.
    • Shell completion can request suggestions from the forwarded program, including for nested relays.
  • Documentation
    • Added guidance on configuring pass-through commands, forwarded arguments, and completion behavior, including command-definition restrictions.

christerswahn and others added 5 commits November 24, 2026 20:46
Resolving the command line typed so far and running the middleware of
its commands in completion mode is now a function of its own, so that
other kinds of completion can run at the leaf command too.

Co-authored-by: Cursor <cursoragent@cursor.com>
A command that overrides passThroughArgs leaves every argument after it
unparsed, to be passed through to another program. That includes --help
and --. The arguments are the remainingPosArgs of the command, as they
were written.

A pass-through command must not be the root command, and must not have
subcommands or command line options.

CommandDefinition gains the passThroughArgs getter, which classes that
implement that interface directly need to add.

Co-authored-by: Cursor <cursoragent@cursor.com>
A pass-through command completes the arguments after it by overriding
completePassThroughArgs, which gets the words typed so far. It is called
with the resolved context of the command, inside the middleware of the
commands, in completion mode. The default is file completion.

Co-authored-by: Cursor <cursoragent@cursor.com>
requestCompletionFrom asks another program for the completion of some
words, by running its __complete request, and returns the response as it
is. A pass-through command uses it to complete the arguments that it
passes to that program.

For this, CompletionResponse.tryParse parses a response in the wire
format, and the name of the request, completeRequestCommand, is public.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

This change adds pass-through commands that preserve arguments for execution or completion. It also adds completion response parsing and a process relay for forwarding completion requests to another executable.

Changes: Pass-through commands and completion

Layer / File(s) Summary
Pass-through command parsing and execution
packages/config/lib/src/config/arg_parser/*, packages/config/lib/src/command/abstract_command.dart, packages/config/lib/src/command/usage/invocation_synopsis.dart, packages/config/lib/src/command/command_runner.dart, packages/config/test/config/arg_parser/*, packages/config/test/command/command_line_run_test.dart, packages/config/README_command.md
Commands can enable pass-through arguments. The parser leaves arguments after the selected command unparsed and validates pass-through command definitions. Tests cover argument handling and definition restrictions.
Pass-through completion
packages/config/lib/src/command/completion/completion_at_leaf.dart, packages/config/lib/src/command/completion/completion_engine.dart, packages/config/lib/src/command/completion/option_value_completion.dart, packages/config/test/command/completion/completion_engine_test.dart, packages/config/README_command.md
The completion engine resolves pass-through arguments through command middleware and calls the leaf command’s completion method. Option-value completion uses the shared leaf-completion traversal.
Completion protocol and executable relay
packages/config/lib/src/command/completion/*, packages/config/lib/src/command/command_runner.dart, packages/config/test/command/completion/completion_relay_test.dart, packages/config/test/command/completion/fixtures/completion_cli.dart, packages/config/test/command/completion/shell_integration_test.dart
The completion protocol defines the request identifier and parses responses. The relay runs a target executable and returns its completion response. Tests cover process failures, nested relays, and shell completion.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Shell
  participant CommandRunner
  participant CompletionEngine
  participant RelayCommand
  participant TargetExecutable
  Shell->>CommandRunner: Sends completion request
  CommandRunner->>CompletionEngine: Routes completion request
  CompletionEngine->>RelayCommand: Calls completePassThroughArgs with words
  RelayCommand->>TargetExecutable: Runs __complete with words
  TargetExecutable-->>RelayCommand: Returns completion response
  RelayCommand-->>CompletionEngine: Returns parsed completion response
Loading

Possibly related PRs

  • serverpod/cli_tools#130: Defines the command parser behavior that this change extends to preserve pass-through arguments.
  • serverpod/cli_tools#145: Changes handling of -- and remaining arguments, which this change also covers for pass-through commands.

Suggested reviewers: nielsenko

Merge Risk: Minimal · up to 219f3

This adds opt-in pass-through commands and a helper that relays shell completion to another executable. Existing commands are unaffected unless they enable the new behavior. The supplied tests cover parsing, execution, completion and the relay's failure cases, and no merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "feat(command): Support completion with external subcommands" matches the main change. The PR adds pass-through commands and a relay that forwards shell completion requests to an external ex…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "feat(command): Support completion with external subcommands" matches the main change. The PR adds pass-through commands and a relay that forwards shell completion requests to an external executable through __complete, so completion for external subcommands is supported. The title names the primary feature, follows a conventional commit style, and is specific enough for a teammate reviewing history.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 7bf19f9c-1ee9-4449-96f7-cb3b701d059d
Commits

Reviewing files that changed from the base of the PR and between cf0b147 and 219f39b.

Files selected for processing: 19

  • packages/config/README_command.md
  • packages/config/lib/src/command/abstract_command.dart
  • packages/config/lib/src/command/command_runner.dart
  • packages/config/lib/src/command/completion/completion.dart
  • packages/config/lib/src/command/completion/completion_at_leaf.dart
  • packages/config/lib/src/command/completion/completion_engine.dart
  • packages/config/lib/src/command/completion/completion_protocol.dart
  • packages/config/lib/src/command/completion/completion_relay.dart
  • packages/config/lib/src/command/completion/option_value_completion.dart
  • packages/config/lib/src/command/usage/invocation_synopsis.dart
  • packages/config/lib/src/config/arg_parser/command_definition.dart
  • packages/config/lib/src/config/arg_parser/parser.dart
  • packages/config/test/command/command_line_run_test.dart
  • packages/config/test/command/completion/completion_engine_test.dart
  • packages/config/test/command/completion/completion_relay_test.dart
  • packages/config/test/command/completion/fixtures/completion_cli.dart
  • packages/config/test/command/completion/shell_integration_test.dart
  • packages/config/test/config/arg_parser/arg_parser_test_support.dart
  • packages/config/test/config/arg_parser/scan_and_parse_commands_test.dart

Included review availability: This review used your included allowance. 2 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 3 reviews per hour.

@christerswahn
christerswahn merged commit cd43405 into main Nov 25, 2026
36 checks passed
@christerswahn
christerswahn deleted the new-better-command branch November 25, 2026 10:10
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