Skip to content

Support option completion for default subcommands - #965

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

pentaoa wants to merge 5 commits 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, dump-help and manual snapshots

Testing

  • Generated Bash, Zsh, and Fish scripts match the updated math completion snapshots.
  • Tests/ArgumentParserExampleTests/CompletionTests contains command-line/Tab/output fixtures using the existing Math → Add hierarchy. All 9 real-shell cases pass with bash, zsh and fish; the original scripts fail the 6 omitted-default cases. The runner uses Python's standard library and a PTY; its README includes the reproduction command.
  • math and generate-manual build successfully. The three dump-help/manual snapshot changes correspond to the inferred defaultSubcommand: add metadata and the now-optional subcommand in the synopsis.
  • CompletionExampleTests registers all shell/fixture pairs with Swift Testing and reports driver failures as test failures. All nine cases passed through the actual Swift Testing entry point in an isolated build with the package-generated resource accessor. The full package suite remains blocked locally by missing XCTest in this Command Line Tools-only installation; the repository CI matrix must validate it.
  • Fixed the Python driver license header, import order and line lengths reported by CI. The POSIX cleanup API is covered by the repository's existing unacceptable-language ignore mechanism.

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.

@rauhul

rauhul commented Sep 13, 2026

Copy link
Copy Markdown
Collaborator

Tbh for changes like this I would really prefer we have a fixture for each of bash/zsh/fish with:

  • A ParsableCommand (or hierarchy)
  • A example command line with a tab location e.g. math ad<DEBUG>d 1
  • The expected completion output

That would allow us to verify the end user experience is what we expect.

@pentaoa

pentaoa commented Sep 14, 2026

Copy link
Copy Markdown
Author

Added interactive fixtures using the existing Math → Add hierarchy in Tests/CompletionTests. Each case specifies the command line, Tab location and resulting line; the runner generates the scripts and exercises real bash/zsh/fish line editors in a PTY. It covers the omitted default command, a cursor before a suffix, and nested value completion.

All 9 cases pass locally; the original scripts fail the 6 omitted-default cases. The README includes the command to reproduce this without Python dependencies. I also updated the three dump-help/manual snapshots missed when switching to the inferred default command name, which caused the CI failures.

The full Swift Testing suite remains unavailable on my Command Line Tools-only host, so I haven't claimed a local full-suite pass. The example and manual generator build successfully.

@rauhul

rauhul commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

this is very cool, though for the harness to be a good citizen in this repo it would be preferable for the tests to run via swift-testing

@pentaoa

pentaoa commented Sep 15, 2026

Copy link
Copy Markdown
Author

Added CompletionExampleTests to the existing example test target. swift test --filter CompletionExampleTests now runs each installed shell/fixture pair separately and reports the PTY driver output on failure; the driver and fixtures are package resources.

All nine cases passed through Swift Testing in an isolated build using the package-generated resource accessor. The full package suite is still blocked locally by missing XCTest in my Command Line Tools installation. I also fixed the license header and Python lint failures from CI.

@natecook1000
natecook1000 force-pushed the fix/488-default-subcommand-completions branch from 9feafa3 to bac1883 Compare October 24, 2026 18:48

This branch has not been deployed

No deployments
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

2 participants