From a588a8e21ffcb3471ad9be6aa6b1f3046de39136 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Tue, 9 Aug 2022 17:02:02 +0300 Subject: [PATCH] Make config_file an optional argument. It can be generated on FRE - Make config_file an optional arg. It defaults to default khoj config dir - Return args.config as None if no config_file explicitly passed by user - Parent can use args.config = None as signal to trigger first run experience --- src/utils/cli.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/utils/cli.py b/src/utils/cli.py index a4d8ac2b..e4d91e0f 100644 --- a/src/utils/cli.py +++ b/src/utils/cli.py @@ -9,10 +9,11 @@ import yaml from src.utils.helpers import get_absolute_path, resolve_absolute_path from src.utils.rawconfig import FullConfig + def cli(args=None): # Setup Argument Parser for the Commandline Interface parser = argparse.ArgumentParser(description="Start Khoj; A Natural Language Search Engine for your personal Notes, Transactions and Photos") - parser.add_argument('config_file', type=pathlib.Path, help="YAML file to configure Khoj") + parser.add_argument('--config-file', '-c', default='~/.khoj/khoj.yml', type=pathlib.Path, help="YAML file to configure Khoj") parser.add_argument('--regenerate', action='store_true', default=False, help="Regenerate model embeddings from source files. Default: false") parser.add_argument('--verbose', '-v', action='count', default=0, help="Show verbose conversion logs. Default: 0") parser.add_argument('--host', type=str, default='127.0.0.1', help="Host address of the server. Default: 127.0.0.1") @@ -22,14 +23,14 @@ def cli(args=None): args = parser.parse_args(args) if not resolve_absolute_path(args.config_file).exists(): - raise ValueError(f"Config file {args.config_file} does not exist") + args.config = None + else: + # Read Config from YML file + config_from_file = None + with open(get_absolute_path(args.config_file), 'r', encoding='utf-8') as config_file: + config_from_file = yaml.safe_load(config_file) - # Read Config from YML file - config_from_file = None - with open(get_absolute_path(args.config_file), 'r', encoding='utf-8') as config_file: - config_from_file = yaml.safe_load(config_file) - - # Parse, Validate Config in YML file - args.config = FullConfig.parse_obj(config_from_file) + # Parse, Validate Config in YML file + args.config = FullConfig.parse_obj(config_from_file) return args \ No newline at end of file