Add shell autocomplete support for openai CLI#2975
Add shell autocomplete support for openai CLI#2975alpnix wants to merge 1 commit intoopenai:mainfrom
Conversation
Implements openai#843 by adding comprehensive shell completion for bash, zsh, fish, and PowerShell. Features: - generates completion scripts - --instructions flag shows installation steps - Autocompletes commands, subcommands, and flags - Context-aware suggestions - No external dependencies Supported shells: - bash (Linux, macOS, WSL) - zsh (macOS default) - fish (cross-platform) - PowerShell (Windows, cross-platform) Usage: openai completion bash openai completion zsh --instructions eval "$(openai completion bash)" Implementation: - New _completion.py module with shell-specific scripts - Integrated into existing CLI via subparser - Follows patterns from gh CLI and stripe CLI - Comprehensive documentation in COMPLETION.md Closes openai#843
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 98df1c1746
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| help="Show installation instructions" | ||
| ) | ||
|
|
||
| def completion_handler(args: Any) -> None: |
There was a problem hiding this comment.
Call completion handler with parsed arguments
The new completion_handler requires a positional args, but this subparser never sets args_model, so _main() follows the no-model path and calls parsed.func() with zero arguments. As a result, any openai completion ... invocation raises TypeError instead of printing a completion script or instructions, making the new command unusable for all shells.
Useful? React with 👍 / 👎.
| prev="${COMP_WORDS[COMP_CWORD-1]}" | ||
|
|
||
| # Top-level commands | ||
| opts="api chat audio models files fine-tuning embeddings images completions completion --help --version" |
There was a problem hiding this comment.
Complete only valid top-level CLI commands
The Bash completion candidates include chat, audio, models, etc. as top-level commands, but the parser only registers api, tools, and completion at the top level. This causes tab completion to suggest commands that immediately fail and omits tools, so the generated completion script is inaccurate for normal CLI usage.
Useful? React with 👍 / 👎.
Summary
Implements #843 by adding comprehensive shell autocomplete for the
openaiCLI, matching the functionality found in popular CLIs like GitHub CLI and Stripe CLI.Changes
New Files:
src/openai/cli/_completion.py- Completion script generator for all shellsCOMPLETION.md- Comprehensive usage and installation documentationModified:
src/openai/cli/_cli.py- Addedcompletionsubcommand integrationFeatures
Supported Shells
Usage
What Gets Autocompleted
api,chat,audio,models, etc.)--api-key,--organization,--help, etc.)completioncommand itselfImplementation Details
ghandstripeCLIsTesting
Installation Instructions
Each shell has simple installation:
Bash:
Zsh:
Fish:
PowerShell:
Example Usage
Benefits
Closes #843