From 253dc4ba37807d778e2874bf2f2c50db228f3d4b Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Tue, 14 Dec 2021 17:57:19 +0100 Subject: [PATCH] Fix default file path Fixed the location of the default file path to mirror the one mentioned in the README. It now roughly adheres to the XDG home data location as its default. Added simple path validation for passed in file paths - will not see if its readable/writable but simply look for the file's existence and error out otherwise. --- options.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/options.py b/options.py index faa29e1..111242e 100644 --- a/options.py +++ b/options.py @@ -1,4 +1,5 @@ import os +import sys import argparse from dataclasses import dataclass, field from typing import List @@ -6,8 +7,9 @@ from typing import List @dataclass class Options: - # can be changed - jrnl_fname: str = f"{os.path.expanduser('~')}/documents/records/todo.md" + jrnl_fname: str = field( + default_factory=lambda: f"{os.environ.get('XDG_DATA_HOME', os.environ.get('HOME'))}/jrnl/journal.txt" + ) todo_block_title: str = "todotxt" dryrun: bool = False taskwarrior_log_completed: bool = True @@ -36,6 +38,7 @@ def init(): parse_cmdline_args(parser, opt) if opt.dryrun: dryrun_show_options(opt) + validate_opts(opt) return opt @@ -94,3 +97,9 @@ def parse_cmdline_args(parser, options): options.todo_block_title = args.blocktitle return options + + +def validate_opts(options): + if not os.path.isfile(options.jrnl_fname): + print(f"{options.jrnl_fname} does not seem to be a file. Aborting.") + sys.exit(1)