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:
parent
417536f1b5
commit
253dc4ba37
1 changed files with 11 additions and 2 deletions
13
options.py
13
options.py
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import argparse
|
import argparse
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from typing import List
|
from typing import List
|
||||||
|
@ -6,8 +7,9 @@ from typing import List
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Options:
|
class Options:
|
||||||
# can be changed
|
jrnl_fname: str = field(
|
||||||
jrnl_fname: str = f"{os.path.expanduser('~')}/documents/records/todo.md"
|
default_factory=lambda: f"{os.environ.get('XDG_DATA_HOME', os.environ.get('HOME'))}/jrnl/journal.txt"
|
||||||
|
)
|
||||||
todo_block_title: str = "todotxt"
|
todo_block_title: str = "todotxt"
|
||||||
dryrun: bool = False
|
dryrun: bool = False
|
||||||
taskwarrior_log_completed: bool = True
|
taskwarrior_log_completed: bool = True
|
||||||
|
@ -36,6 +38,7 @@ def init():
|
||||||
parse_cmdline_args(parser, opt)
|
parse_cmdline_args(parser, opt)
|
||||||
if opt.dryrun:
|
if opt.dryrun:
|
||||||
dryrun_show_options(opt)
|
dryrun_show_options(opt)
|
||||||
|
validate_opts(opt)
|
||||||
return opt
|
return opt
|
||||||
|
|
||||||
|
|
||||||
|
@ -94,3 +97,9 @@ def parse_cmdline_args(parser, options):
|
||||||
options.todo_block_title = args.blocktitle
|
options.todo_block_title = args.blocktitle
|
||||||
|
|
||||||
return options
|
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)
|
||||||
|
|
Loading…
Reference in a new issue