Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions helpers/shell-completion.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
# openai CLI Shell Completion
# Generated for issue #843: Add shell auto completion

_openai_complete() {
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"

opts="api_base api_key api_type azure_ad_token azure_endpoint help organization proxy verbose version"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Emit real CLI flags in completion candidates

The completion list is built from api_base, api_key, etc., but the CLI parser actually accepts hyphenated, prefixed flags like --api-base, --api-key, --azure-endpoint (src/openai/cli/_cli.py, _build_parser). Because Bash completion matches the current token prefix, a common flow like typing openai --a<Tab> yields no matches, and any suggestions that do appear are not valid command-line flags, so the new completion script is effectively broken for top-level options.

Useful? React with 👍 / 👎.


case "${prev}" in
-b|--api-base|-k|--api-key|-o|--organization|-p|--proxy|-t|--api-type|--api-version|--azure-endpoint|--azure-ad-token)
return 0
;;
esac

COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
}

complete -F _openai_complete openai