Skip to content

Add dependency-free CLI shell completion#3129

Open
xodn348 wants to merge 1 commit intoopenai:mainfrom
xodn348:fix/843-cli-shell-completion
Open

Add dependency-free CLI shell completion#3129
xodn348 wants to merge 1 commit intoopenai:mainfrom
xodn348:fix/843-cli-shell-completion

Conversation

@xodn348
Copy link
Copy Markdown

@xodn348 xodn348 commented Apr 27, 2026

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:

  • top-level CLI commands
  • api subcommands
  • tools subcommands
  • supported completion shell names

I noticed #1603 also attempted this with argcomplete; this version keeps the package dependency-free and avoids an extra optional install step.

Testing:

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

Results: 4 targeted tests passed; ruff passed; mypy passed; py_compile passed.

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.
@xodn348 xodn348 requested a review from a team as a code owner April 27, 2026 21:46
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 shell auto completion for different shell, like bash, zsh, fish, powershell

1 participant