fix: Reintegrate env var parsing
Was removed from parsing when conf parsing was added, now re-added into configuration parsing.
This commit is contained in:
parent
f1f3041928
commit
96422d254b
1 changed files with 40 additions and 32 deletions
42
topen.py
42
topen.py
|
|
@ -16,18 +16,9 @@ from pathlib import Path
|
||||||
|
|
||||||
from tasklib import Task, TaskWarrior
|
from tasklib import Task, TaskWarrior
|
||||||
|
|
||||||
# TODO: This should not assume XDG compliance for
|
|
||||||
# no-setup TW instances.
|
|
||||||
TASK_RC = os.getenv("TASKRC", "~/.config/task/taskrc")
|
|
||||||
TASK_DATA_DIR = os.getenv("TASKDATA", "~/.local/share/task")
|
|
||||||
|
|
||||||
TOPEN_DIR = os.getenv("TOPEN_DIR")
|
|
||||||
TOPEN_EXT = os.getenv("TOPEN_EXT")
|
|
||||||
TOPEN_ANNOT = os.getenv("TOPEN_ANNOT")
|
|
||||||
TOPEN_EDITOR = os.getenv("EDITOR") or os.getenv("VISUAL")
|
|
||||||
TOPEN_QUIET = os.getenv("TOPEN_QUIET")
|
|
||||||
|
|
||||||
DEFAULTS_DICT = {
|
DEFAULTS_DICT = {
|
||||||
|
"task_rc": "~/.config/task/taskrc",
|
||||||
|
"task_data": "~/.local/share/task",
|
||||||
"notes_dir": "~/.local/share/task/notes",
|
"notes_dir": "~/.local/share/task/notes",
|
||||||
"notes_ext": "md",
|
"notes_ext": "md",
|
||||||
"notes_annot": "Note",
|
"notes_annot": "Note",
|
||||||
|
|
@ -43,7 +34,8 @@ def parse_conf(conf_file: Path) -> dict:
|
||||||
with open(conf_file.expanduser()) as f:
|
with open(conf_file.expanduser()) as f:
|
||||||
c.read_string("[DEFAULT]\n" + f.read())
|
c.read_string("[DEFAULT]\n" + f.read())
|
||||||
|
|
||||||
res = {
|
return _filtered_dict(
|
||||||
|
{
|
||||||
"notes_dir": c.get("DEFAULT", "notes_dir"),
|
"notes_dir": c.get("DEFAULT", "notes_dir"),
|
||||||
"notes_ext": c.get("DEFAULT", "notes_ext"),
|
"notes_ext": c.get("DEFAULT", "notes_ext"),
|
||||||
"notes_annot": c.get("DEFAULT", "notes_annot"),
|
"notes_annot": c.get("DEFAULT", "notes_annot"),
|
||||||
|
|
@ -51,10 +43,23 @@ def parse_conf(conf_file: Path) -> dict:
|
||||||
"notes_quiet": c.get("DEFAULT", "notes_quiet"),
|
"notes_quiet": c.get("DEFAULT", "notes_quiet"),
|
||||||
"task_data": c.get("DEFAULT", "data.location"),
|
"task_data": c.get("DEFAULT", "data.location"),
|
||||||
}
|
}
|
||||||
return _filtered_dict(res)
|
)
|
||||||
|
|
||||||
|
|
||||||
def parse_env() -> dict: ...
|
def parse_env() -> dict:
|
||||||
|
# TODO: This should not assume XDG compliance for
|
||||||
|
# no-setup TW instances.
|
||||||
|
return _filtered_dict(
|
||||||
|
{
|
||||||
|
"task_rc": os.getenv("TASKRC"),
|
||||||
|
"task_data": os.getenv("TASKDATA"),
|
||||||
|
"notes_dir": os.getenv("TOPEN_DIR"),
|
||||||
|
"notes_ext": os.getenv("TOPEN_EXT"),
|
||||||
|
"notes_annot": os.getenv("TOPEN_ANNOT"),
|
||||||
|
"notes_editor": os.getenv("TOPEN_EDITOR") or os.getenv("EDITOR") or os.getenv("VISUAL"),
|
||||||
|
"notes_quiet": os.getenv("TOPEN_QUIET"),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def parse_cli() -> dict:
|
def parse_cli() -> dict:
|
||||||
|
|
@ -90,7 +95,8 @@ you view the task.
|
||||||
_ = parser.add_argument("--task-data", help="Location of taskwarrior data")
|
_ = parser.add_argument("--task-data", help="Location of taskwarrior data")
|
||||||
|
|
||||||
p = parser.parse_args()
|
p = parser.parse_args()
|
||||||
res = {
|
return _filtered_dict(
|
||||||
|
{
|
||||||
"task_id": p.id,
|
"task_id": p.id,
|
||||||
"task_data": p.task_data,
|
"task_data": p.task_data,
|
||||||
"notes_dir": p.notes_dir,
|
"notes_dir": p.notes_dir,
|
||||||
|
|
@ -99,7 +105,7 @@ you view the task.
|
||||||
"notes_editor": p.editor,
|
"notes_editor": p.editor,
|
||||||
"notes_quiet": p.quiet,
|
"notes_quiet": p.quiet,
|
||||||
}
|
}
|
||||||
return _filtered_dict(res)
|
)
|
||||||
|
|
||||||
|
|
||||||
IS_QUIET = False
|
IS_QUIET = False
|
||||||
|
|
@ -113,7 +119,9 @@ def whisper(text: str) -> None:
|
||||||
def main():
|
def main():
|
||||||
# TODO: Don't forget to expand user (path.expanduser) and expand vars (os.path.expandvars)
|
# TODO: Don't forget to expand user (path.expanduser) and expand vars (os.path.expandvars)
|
||||||
# Should probably be done when 'parsing' option object initially
|
# Should probably be done when 'parsing' option object initially
|
||||||
cfg = parse_conf(Path(TASK_RC)) | parse_cli()
|
pre_cfg = parse_env() | parse_cli()
|
||||||
|
conf_file = Path(pre_cfg.get("task_rc", DEFAULTS_DICT["task_rc"]))
|
||||||
|
cfg = parse_conf(conf_file) | pre_cfg
|
||||||
|
|
||||||
if not cfg["task_id"]:
|
if not cfg["task_id"]:
|
||||||
_ = sys.stderr.write("Please provide task ID as argument.\n")
|
_ = sys.stderr.write("Please provide task ID as argument.\n")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue