diff options
| author | Furkan Sahin <furkan-dev@proton.me> | 2023-05-09 15:57:05 -0500 |
|---|---|---|
| committer | Furkan Sahin <furkan-dev@proton.me> | 2023-05-09 15:57:05 -0500 |
| commit | 65528bd77d156d568252ebf81034b364edd07540 (patch) | |
| tree | 710c89788e193620be368d938eab2a2033739175 /src/gpt_chat_cli/main.py | |
| parent | f1cb281ee948e693ec3be1b9dfcde379d4b04ecc (diff) | |
Rewrote the argparsing functionality to enable autocompletion via the "kislyuk/argcomplete" package.
This essentially means:
- `argparsing.py` does a minimal amount of work to initialize the arg parser.
Then it attempts dynamic completion.
- `argvalidation.py` processes the raw arguments parsed in
`argparsing.py`, validates them, issues warnings (if required), and
splits them into logical groupings
- Commands in `gcli.py` have been moved to `cmd.py`
- `main.py` provides an initial control path to call these functions in
succession
Diffstat (limited to 'src/gpt_chat_cli/main.py')
| -rw-r--r-- | src/gpt_chat_cli/main.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/gpt_chat_cli/main.py b/src/gpt_chat_cli/main.py new file mode 100644 index 0000000..77d2708 --- /dev/null +++ b/src/gpt_chat_cli/main.py @@ -0,0 +1,38 @@ +def main(): + # defer other imports until autocomplete has finished + from .argparsing import parse_raw_args_or_complete + + raw_args = parse_raw_args_or_complete() + + # post process and validate + from .argvalidation import ( + Arguments, + post_process_raw_args + ) + + args = post_process_raw_args( raw_args ) + + # populate key + import openai + + openai.api_key = args.openai_key + + # execute relevant command + from .cmd import ( + version, + list_models, + interactive, + singleton, + ) + + if args.version: + version() + elif args.list_models: + list_models() + elif args.interactive: + interactive(args) + else: + singleton(args) + +if __name__ == "__main__": + main() |
