Skip to content

Commit

Permalink
Merge pull request #15 from Tienbruh/hoonbranch
Browse files Browse the repository at this point in the history
add try except block for importing argcomplete and changes to the readme
  • Loading branch information
Tienbruh authored Sep 4, 2024
2 parents 984a02e + 6d2e5fa commit 5eda534
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,11 @@ An example of using the client with Microsoft Entra ID (formerly known as Azure
## Activating CLI Autocomplete
Use the following commands to activate CLI autocompletion for each shell.

Install `openai` with `[cli]` option to install argcomplete.
```shell
pip install openai[cli]
```

### Bash & Zsh
Use this command to register `openai` for argument completion using argcomplete for the current terminal session:
```shell
Expand Down
8 changes: 6 additions & 2 deletions src/openai/cli/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sys
import logging
import argparse
import argcomplete

from typing import Any, List, Type, Optional
from typing_extensions import ClassVar

Expand Down Expand Up @@ -165,7 +165,11 @@ def _parse_args(parser: argparse.ArgumentParser) -> tuple[argparse.Namespace, Ar

def _main() -> None:
parser = _build_parser()
argcomplete.autocomplete(parser)
try:
import argcomplete
argcomplete.autocomplete(parser)
except ImportError:
pass
parsed, args, unknown = _parse_args(parser)

if args.verbosity != 0:
Expand Down

0 comments on commit 5eda534

Please sign in to comment.