ref: Reformat build_config function
Make the internal function logic a litte clearer
This commit is contained in:
parent
9b2dc37279
commit
6517eb3971
1 changed files with 4 additions and 5 deletions
9
topen.py
9
topen.py
|
|
@ -267,17 +267,16 @@ class TConf:
|
||||||
|
|
||||||
def build_config() -> TConf:
|
def build_config() -> TConf:
|
||||||
"""Return final configuration object."""
|
"""Return final configuration object."""
|
||||||
cli = parse_cli()
|
defaults = {k: opt.default for k, opt in OPTIONS.items()}
|
||||||
env = parse_env()
|
env = parse_env()
|
||||||
|
cli = parse_cli()
|
||||||
|
|
||||||
rc_path = Path(
|
rc_path = Path(
|
||||||
cli.get("task_rc") or env.get("task_rc") or OPTIONS["task_rc"].default
|
cli.get("task_rc") or env.get("task_rc") or OPTIONS["task_rc"].default
|
||||||
).expanduser()
|
).expanduser()
|
||||||
|
defaults["task_rc"] = rc_path # use XDG-included paths
|
||||||
rc = parse_rc(rc_path) if rc_path.exists() else {}
|
rc = parse_rc(rc_path) if rc_path.exists() else {}
|
||||||
|
|
||||||
# we use the 'parsed' XDG-included taskrc locations for defaults
|
|
||||||
defaults = {k: opt.default for k, opt in OPTIONS.items()}
|
|
||||||
defaults["task_rc"] = rc_path
|
|
||||||
|
|
||||||
merged = defaults | rc | env | cli # later wins
|
merged = defaults | rc | env | cli # later wins
|
||||||
return TConf.from_dict({k: v for k, v in merged.items() if v is not None})
|
return TConf.from_dict({k: v for k, v in merged.items() if v is not None})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue