diff --git a/src/utils/cli.py b/src/utils/cli.py index 7a21ee4a..152c1805 100644 --- a/src/utils/cli.py +++ b/src/utils/cli.py @@ -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 diff --git a/tests/test_cli.py b/tests/test_cli.py index 5976dbdd..6fb0b73f 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,5 +1,9 @@ # Standard Modules from pathlib import Path +from random import random + +# External Modules +import pytest # Internal Packages from src.utils.cli import cli @@ -9,7 +13,7 @@ from src.utils.cli import cli # ---------------------------------------------------------------------------------------------------- def test_cli_minimal_default(): # Act - actual_args = cli(['--config-file=tests/data/config.yml']) + actual_args = cli(['tests/data/config.yml']) # Assert assert actual_args.config_file == Path('tests/data/config.yml') @@ -17,22 +21,15 @@ def test_cli_minimal_default(): assert actual_args.verbose == 0 # ---------------------------------------------------------------------------------------------------- -def test_cli_flags(): +def test_cli_invalid_config_file_path(): # Act - actual_args = cli(['--config-file=tests/data/config.yml', - '--regenerate', - '-vvv']) - - # Assert - assert actual_args.config_file == Path('tests/data/config.yml') - assert actual_args.regenerate == True - assert actual_args.verbose == 3 - + with pytest.raises(ValueError): + cli([f"non-existent-khoj-{random()}.yml"]) # ---------------------------------------------------------------------------------------------------- def test_cli_config_from_file(): # Act - actual_args = cli(['--config-file=tests/data/config.yml', + actual_args = cli(['tests/data/config.yml', '--regenerate', '-vvv'])