Fixed config parsing
This commit is contained in:
parent
a24cdfd72a
commit
ba732934d0
3 changed files with 16 additions and 8 deletions
|
@ -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
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
thing: thing 1
|
||||
thing 2: thing
|
||||
stuff:
|
||||
- thing 1
|
||||
- thing 2
|
||||
- thing 3
|
||||
long things: stuff
|
|
@ -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
|
Reference in a new issue