Add dependency-free CLI shell completion#3129
Open
xodn348 wants to merge 1 commit intoopenai:mainfrom
Open
Conversation
The OpenAI CLI already builds its command tree through argparse, so the completion command reuses that parser structure to emit shell scripts for bash, zsh, fish, and PowerShell instead of adding argcomplete or maintaining hand-written command lists. Constraint: No new runtime dependency for CLI completion.\nRejected: Add argcomplete optional extra | duplicates stale PR openai#1603 and adds dependency/install friction.\nConfidence: medium\nScope-risk: narrow\nTested: PYTHONPATH=src pytest -q tests/test_cli_completion.py; PYTHONPATH=src python -m ruff check src/openai/cli/_cli.py src/openai/cli/_completion.py tests/test_cli_completion.py; PYTHONPATH=src python -m ruff format --check src/openai/cli/_cli.py src/openai/cli/_completion.py tests/test_cli_completion.py; PYTHONPATH=src python -m mypy src/openai/cli/_completion.py tests/test_cli_completion.py; python3 -m py_compile src/openai/cli/_cli.py src/openai/cli/_completion.py\nNot-tested: Interactive shell tab-completion in bash/zsh/fish/PowerShell.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #843.
This adds a built-in
openai completion <shell>command for bash, zsh, fish, and PowerShell.The implementation intentionally avoids adding a new dependency. Instead, it reuses the existing argparse command tree to generate completion candidates for:
apisubcommandstoolssubcommandsI noticed #1603 also attempted this with
argcomplete; this version keeps the package dependency-free and avoids an extra optional install step.Testing:
Results: 4 targeted tests passed; ruff passed; mypy passed; py_compile passed.