Skip to content

Support option completion for default subcommands - #965

Open
pentaoa wants to merge 1 commit into
apple:mainfrom
pentaoa:fix/488-default-subcommand-completions
Open

Support option completion for default subcommands#965
pentaoa wants to merge 1 commit into
apple:mainfrom
pentaoa:fix/488-default-subcommand-completions

Conversation

@pentaoa

@pentaoa pentaoa commented Sep 2, 2026

Copy link
Copy Markdown

Adds a default subcommand's named arguments to its parent command's generated completions, so options and flags remain completable when the default subcommand name is omitted.

The completion metadata retains the owning subcommand for custom completion callbacks and removes duplicate option names inherited through nested defaults. Positional arguments are intentionally not merged because they would compete with explicit subcommand names.

Fixes #488.

Checklist

  • I've added tests that validate Bash, Zsh, and Fish output
  • I've followed the code style of the rest of the project
  • I've read the Contribution Guidelines
  • I've updated the existing math completion snapshots

Testing

  • swift build --product ArgumentParser
  • swift format lint --strict on all changed Swift files
  • generated Bash, Zsh, and Fish scripts for the existing math example match the updated snapshots
  • manually exercised Bash completion for the omitted default subcommand and an explicit sibling subcommand

The full Swift test target could not run locally because this host only has Command Line Tools and its SDK does not provide XCTest; the repository CI matrix will run the added tests.

AI assistance: Codex was used to investigate the issue, implement the change, and draft tests and this PR description. I reviewed the diff and verified the behavior described above.

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.

Add completion for default subcommand to supercommand

1 participant