From 4f684f7073149c48ea9dd962b64a8bf7a169a1cf Mon Sep 17 00:00:00 2001 From: flu0r1ne Date: Tue, 9 May 2023 15:57:05 -0500 Subject: 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 --- src/gpt_chat_cli/main.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/gpt_chat_cli/main.py (limited to 'src/gpt_chat_cli/main.py') 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() -- cgit v1.2.3