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.
This commit is contained in:
Marty Oehme 2021-12-14 17:57:19 +01:00
parent 417536f1b5
commit 253dc4ba37
Signed by: Marty
GPG Key ID: B7538B8F50A1C800
1 changed files with 11 additions and 2 deletions

View File

@ -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
class Options:
# can be changed
jrnl_fname: str = f"{os.path.expanduser('~')}/documents/records/"
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:
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.")