feat(completion): add shell completion scripts for bash, zsh, and fish#3194
feat(completion): add shell completion scripts for bash, zsh, and fish#3194lrg913427-dot wants to merge 5 commits intoopenai:mainfrom
Conversation
Add shell auto-completion support for the openai CLI tool. Changes: - completions/openai.bash: Bash completion script - completions/openai.zsh: Zsh completion script - completions/openai.fish: Fish completion script - src/openai/cli/_completions.py: Completion generation module Usage: openai completion bash > ~/.openai-completion.bash openai completion zsh > ~/.openai-completion.zsh openai completion fish > ~/.config/fish/completions/openai.fish Completions include: - All subcommands (api, tools, chat, image, audio, etc.) - Model names with descriptions - Voice options for TTS - Image sizes and quality options - All CLI flags and options Fixes openai#843
Add shell auto-completion support for the openai CLI tool. Changes: - completions/openai.bash: Bash completion script - completions/openai.zsh: Zsh completion script - completions/openai.fish: Fish completion script - src/openai/cli/_completions.py: Completion generation module Usage: openai completion bash > ~/.openai-completion.bash openai completion zsh > ~/.openai-completion.zsh openai completion fish > ~/.config/fish/completions/openai.fish Completions include: - All subcommands (api, tools, chat, image, audio, etc.) - Model names with descriptions - Voice options for TTS - Image sizes and quality options - All CLI flags and options Fixes openai#843
Add shell auto-completion support for the openai CLI tool. Changes: - completions/openai.bash: Bash completion script - completions/openai.zsh: Zsh completion script - completions/openai.fish: Fish completion script - src/openai/cli/_completions.py: Completion generation module Usage: openai completion bash > ~/.openai-completion.bash openai completion zsh > ~/.openai-completion.zsh openai completion fish > ~/.config/fish/completions/openai.fish Completions include: - All subcommands (api, tools, chat, image, audio, etc.) - Model names with descriptions - Voice options for TTS - Image sizes and quality options - All CLI flags and options Fixes openai#843
Add shell auto-completion support for the openai CLI tool. Changes: - completions/openai.bash: Bash completion script - completions/openai.zsh: Zsh completion script - completions/openai.fish: Fish completion script - src/openai/cli/_completions.py: Completion generation module Usage: openai completion bash > ~/.openai-completion.bash openai completion zsh > ~/.openai-completion.zsh openai completion fish > ~/.config/fish/completions/openai.fish Completions include: - All subcommands (api, tools, chat, image, audio, etc.) - Model names with descriptions - Voice options for TTS - Image sizes and quality options - All CLI flags and options Fixes openai#843
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: afe5d6c3f9
ℹ️ 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".
| def register(parser: argparse.ArgumentParser) -> None: | ||
| """Register the completion command.""" | ||
| sub = parser.add_parser( | ||
| "completion", | ||
| help="Generate shell completion scripts", |
There was a problem hiding this comment.
Wire completion subcommand into CLI parser
The new completion command is never reachable because this module's register() function is not invoked anywhere in the CLI bootstrap path. _build_parser() in src/openai/cli/_cli.py only registers api and tools, so openai completion ... will be rejected as an unknown command and the feature introduced by this commit cannot be used.
Useful? React with 👍 / 👎.
| api_commands="chat image audio files models completions fine_tuning" | ||
| tools_commands="fine_tunes" |
There was a problem hiding this comment.
Generate completions for actual dotted API commands
The generated scripts advertise API subcommands like chat, image, and files, but this CLI actually registers dotted commands such as chat.completions.create, images.generate, and files.create. As a result, completion suggestions steer users toward invalid command names and option matching branches (e.g. chat-specific flags) never trigger for real commands, so completions are effectively broken for the API surface.
Useful? React with 👍 / 👎.
- 171 tests covering bash, zsh, and fish completion scripts - Test COMPLETION_SCRIPTS dict structure (3 tests) - Test bash completion: function, registration, subcommands, models, voices, sizes, flags (43 tests) - Test zsh completion: compdef, function, subcommands, models, voices, sizes, qualities, styles, formats, purposes, options (64 tests) - Test fish completion: complete syntax, subcommands, models, voices, sizes, qualities, styles, options (52 tests) - Test cross-shell consistency for models/voices/sizes/subcommands (4 tests) - Test register() CLI argument parsing: all shells, output flag, invalid shell (6 tests) - Test run() stdout/file output and instructions for all shells (10 tests) - Test model list completeness: GPT-4, reasoning, image, audio families (6 tests) - Test script syntax: brace matching, trailing whitespace, newlines (5 tests) - Test option presence in detailed scripts: stream, temperature, max-tokens, prompt (4 tests) - Fix missing 'import sys' in _completions.py (used by run() for stderr)
Summary
Add shell auto-completion support for the
openaiCLI tool.Fixes #843
Changes
New files:
completions/openai.bash— Bash completion scriptcompletions/openai.zsh— Zsh completion scriptcompletions/openai.fish— Fish completion scriptsrc/openai/cli/_completions.py— Completion generation moduleUsage
Features
Completions include:
api,tools,chat,image,audio, etc.)gpt-4o:GPT-4o - Most capable model)alloy,echo,fable,onyx,nova,shimmer)256x256,512x512,1024x1024, etc.)standard,hd)Testing
Notes
openai completion <shell>command