Make config file a positional argument, as it is required

- Test invalid config file path throws. Remove redundant cli test

- Simplify cli parser code
  - Do not need to explicitly check if args.config_file set.
    argparser checks for positional arguments automatically

- Use standard semantics for cli args
  - All positional args are required. Non positional args are optional

- Improve command line --help description
This commit is contained in:
Debanjum Singh Solanky
2022-08-05 00:24:12 +03:00
parent a3b35fbb6e
commit ca5a8bd113
2 changed files with 13 additions and 23 deletions

View File

@@ -10,12 +10,9 @@ from src.utils.helpers import is_none_or_empty, get_absolute_path, resolve_absol
from src.utils.rawconfig import FullConfig
def cli(args=None):
if is_none_or_empty(args):
return None
# Setup Argument Parser for the Commandline Interface
parser = argparse.ArgumentParser(description="Expose API for Khoj")
parser.add_argument('--config-file', '-c', type=pathlib.Path, help="YAML file with user configuration")
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('--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")
@@ -24,12 +21,8 @@ def cli(args=None):
args = parser.parse_args(args)
if not (args.config_file):
print(f"Need --config-file flag to be passed from commandline")
exit(1)
elif not resolve_absolute_path(args.config_file).exists():
print(f"Config file {args.config_file} does not exist")
exit(1)
if not resolve_absolute_path(args.config_file).exists():
raise ValueError(f"Config file {args.config_file} does not exist")
# Read Config from YML file
config_from_file = None