diff --git a/project/config/cli.py b/project/config/cli.py index a79ee74..ed27fa8 100644 --- a/project/config/cli.py +++ b/project/config/cli.py @@ -1,7 +1,8 @@ import click +from project.utils import get_config -CONFIG_DIR = "~/.dfa.yml" - -@click.command('sync') -def cli(): +@click.command('config') +@click.argument('key') +def cli(key): + print(get_config(key)) pass diff --git a/project/config/defaults.yml b/project/config/defaults.yml index e69de29..7f4e101 100644 --- a/project/config/defaults.yml +++ b/project/config/defaults.yml @@ -0,0 +1,7 @@ +thing: thing 1 +thing 2: thing +stuff: + - thing 1 + - thing 2 + - thing 3 +long things: stuff diff --git a/project/config/load.py b/project/utils.py similarity index 73% rename from project/config/load.py rename to project/utils.py index a4cc6a6..4aa3dac 100644 --- a/project/config/load.py +++ b/project/utils.py @@ -14,16 +14,16 @@ def get_config_data(filename): config_file = open(filename) return load(config_file, Loader=Loader) except FileNotFoundError: - return None + return [] -DEFAULT_CONFIG = get_config_data(os.path.join(BASE_DIR, 'defaults.yml')) +DEFAULT_CONFIG = get_config_data(os.path.join(BASE_DIR, 'config' ,'defaults.yml')) USER_CONFIG = get_config_data(os.path.expanduser(USER_CONFIG_DIR)) def get_config(key): - if key in USER_CONFIG: + if USER_CONFIG and key in USER_CONFIG: return USER_CONFIG[key] - elif key in DEFAULT_CONFIG: + elif DEFAULT_CONFIG and key in DEFAULT_CONFIG: return DEFAULT_CONFIG[key] return None