Add --file argument & fixes
cli.py: + added --file argument to specify the todo file. ~ changed the --task handler to use get_task instead. ~ fixed bug w/ printing information on tasks w/ no due date. TodoObject.py: ~ modified type-hinting on get_tasks. ~ modified type-hinting on get_task. ~ fixed bug with get_task returning type Task rather than found task. ~ fixed bug with get_note not listening to the immediate parameter.
This commit is contained in:
parent
ff0f47ae88
commit
134d71f44d
2 changed files with 19 additions and 13 deletions
18
cli.py
18
cli.py
|
@ -1,4 +1,6 @@
|
||||||
#!/bin/python3
|
#!/bin/python3
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
@ -13,11 +15,15 @@ parser.add_argument("-cat", "--category", action="store", help="Category the com
|
||||||
parser.add_argument("-t", "--task", action="store", help="Target a specific task in a category.")
|
parser.add_argument("-t", "--task", action="store", help="Target a specific task in a category.")
|
||||||
parser.add_argument("-i", "--info", action="store_true", help="Print information about the given object.")
|
parser.add_argument("-i", "--info", action="store_true", help="Print information about the given object.")
|
||||||
parser.add_argument("-x", "--complete", action="store_true", help="Toggle a task's completed status.") # x = done, right?
|
parser.add_argument("-x", "--complete", action="store_true", help="Toggle a task's completed status.") # x = done, right?
|
||||||
|
parser.add_argument("-f", "--file", action="store", help="Specify the file to load into a Todo.")
|
||||||
todo = Todo()
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.file is not None:
|
||||||
|
todo = Todo(Path(args.file))
|
||||||
|
else:
|
||||||
|
todo = Todo()
|
||||||
|
|
||||||
def print_incomplete_tasks(data: TodoObject):
|
def print_incomplete_tasks(data: TodoObject):
|
||||||
if len(data.get_tasks(complete=False)) > 0:
|
if len(data.get_tasks(complete=False)) > 0:
|
||||||
print("\n--- Incomplete Task(s) ---")
|
print("\n--- Incomplete Task(s) ---")
|
||||||
|
@ -38,9 +44,8 @@ if args.category is not None:
|
||||||
|
|
||||||
# --task handler
|
# --task handler
|
||||||
if args.task is not None:
|
if args.task is not None:
|
||||||
for i in data.get_tasks():
|
args.task = f".*{args.task}"
|
||||||
if re.match(args.task, i.text, re.IGNORECASE):
|
data = data.get_task(args.task)
|
||||||
data = i
|
|
||||||
|
|
||||||
# --done handler
|
# --done handler
|
||||||
if args.complete:
|
if args.complete:
|
||||||
|
@ -72,7 +77,8 @@ if args.info:
|
||||||
elif isinstance(data, Task):
|
elif isinstance(data, Task):
|
||||||
print("Category: ", data.task_category().text)
|
print("Category: ", data.task_category().text)
|
||||||
print("Task:", data.text)
|
print("Task:", data.text)
|
||||||
print("Due Date:", data.date.strftime("%b %d %Y"))
|
if data.date is not None:
|
||||||
|
print("Due Date:", data.date.strftime("%b %d %Y"))
|
||||||
print("Complete:", data.complete)
|
print("Complete:", data.complete)
|
||||||
else:
|
else:
|
||||||
print("Don't know how we ended up here. :/")
|
print("Don't know how we ended up here. :/")
|
||||||
|
|
|
@ -99,7 +99,7 @@ class TodoObject:
|
||||||
parent.children.append(self)
|
parent.children.append(self)
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
|
|
||||||
def get_tasks(self, immediate = False, complete: Optional[bool] = None) -> list[Task]:
|
def get_tasks(self, immediate: bool = False, complete: Optional[bool] = None) -> list[Task]:
|
||||||
"""Get all tasks from the children of the TodoObject.
|
"""Get all tasks from the children of the TodoObject.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
@ -118,7 +118,7 @@ class TodoObject:
|
||||||
output.append(child)
|
output.append(child)
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def get_task(self, regex: str, immediate = False, complete: Optional[bool] = None) -> Task:
|
def get_task(self, regex: str, immediate: bool = False, complete: Optional[bool] = None) -> Task:
|
||||||
"""Get a specific task from a supplied regular expression.
|
"""Get a specific task from a supplied regular expression.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
@ -129,12 +129,12 @@ class TodoObject:
|
||||||
Returns:
|
Returns:
|
||||||
Task: [description]
|
Task: [description]
|
||||||
"""
|
"""
|
||||||
for task in self.get_tasks(self, immediate, complete):
|
for task in self.get_tasks(immediate, complete):
|
||||||
if re.match(regex, task.text):
|
if re.match(regex, task.text):
|
||||||
return Task
|
return task
|
||||||
|
|
||||||
|
|
||||||
def get_categories(self, immediate = False) -> list[Category]:
|
def get_categories(self, immediate: bool = False) -> list[Category]:
|
||||||
"""Gets all categories from children of the TodoObject.
|
"""Gets all categories from children of the TodoObject.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
@ -161,7 +161,7 @@ class TodoObject:
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
immediate (bool, optional): Whether or not it should return immeduate children only. Defaults to False.
|
immediate (bool, optional): Whether or not it should return immeduate children only. Defaults to False.
|
||||||
|
c
|
||||||
Returns:
|
Returns:
|
||||||
Note: Returns all notes found.
|
Note: Returns all notes found.
|
||||||
"""
|
"""
|
||||||
|
@ -177,7 +177,7 @@ class TodoObject:
|
||||||
Returns:
|
Returns:
|
||||||
Note: [description]
|
Note: [description]
|
||||||
"""
|
"""
|
||||||
for note in self.get_notes():
|
for note in self.get_notes(immediate):
|
||||||
if re.match(regex, note.text):
|
if re.match(regex, note.text):
|
||||||
return note
|
return note
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue