jrnlwarrior/options.py

82 lines
2.1 KiB
Python
Raw Normal View History

2021-10-31 15:20:41 +00:00
import os
import argparse
from dataclasses import dataclass, field
from typing import List
2021-10-31 15:20:41 +00:00
@dataclass
class Options:
2021-10-31 16:06:28 +00:00
# can be changed
2021-10-31 15:20:41 +00:00
jrnl_fname: str = f"{os.path.expanduser('~')}/documents/records/todo.md"
todo_block_title: str = "todotxt"
dryrun: bool = False
taskwarrior_log_completed: bool = True
taskwarrior_add_incomplete: bool = True
taskwarrior_fill_today: bool = True
2021-10-31 16:06:28 +00:00
# can not yet be changed
taskwarrior_overrides: List = field(
default_factory=lambda: [
"rc.context=none",
"rc.verbose=nothing",
"rc.hooks=0",
]
)
regex_task_completed: str = r"(?:x|\[x\])"
regex_task_incomplete: str = r"\[ \]"
2021-10-31 15:20:41 +00:00
def init():
opt = Options()
parse_cmdline_args(opt)
if opt.dryrun:
dryrun_show_options(opt)
2021-10-31 15:20:41 +00:00
return opt
def dryrun_show_options(options):
2021-10-31 15:20:41 +00:00
print(options)
def parse_cmdline_args(options):
parser = argparse.ArgumentParser()
parser.add_argument(
"-n", "--dryrun", help="only simulate and print changes", action="store_true"
)
parser.add_argument("-f", "--file", help="the jrnl file to ingest")
parser.add_argument("-b", "--blocktitle", help="the jrnl file to ingest")
parser.add_argument(
"-L",
"--nologging",
help="don't log done todo items to taskwarrior",
action="store_true",
)
parser.add_argument(
"-I",
"--noincomplete",
help="don't add incomplete todo items to taskwarrior",
action="store_true",
)
parser.add_argument(
"-T",
"--nofilltoday",
help="don't add today's todo items as entry to file",
action="store_true",
)
2021-10-31 15:20:41 +00:00
args = parser.parse_args()
if args.dryrun:
options.dryrun = True
if args.nologging:
options.taskwarrior_log_completed = False
if args.noincomplete:
options.taskwarrior_add_incomplete = False
if args.nofilltoday:
options.taskwarrior_fill_today = False
2021-10-31 15:20:41 +00:00
if args.file:
options.jrnl_fname = args.file
if args.blocktitle:
options.todo_block_title = args.blocktitle
return options