diff --git a/cli.py b/cli.py index c2c3426..0e349be 100755 --- a/cli.py +++ b/cli.py @@ -1,4 +1,6 @@ #!/bin/python3 +from pathlib import Path + import argparse 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("-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? - -todo = Todo() +parser.add_argument("-f", "--file", action="store", help="Specify the file to load into a Todo.") args = parser.parse_args() +if args.file is not None: + todo = Todo(Path(args.file)) +else: + todo = Todo() + def print_incomplete_tasks(data: TodoObject): if len(data.get_tasks(complete=False)) > 0: print("\n--- Incomplete Task(s) ---") @@ -38,9 +44,8 @@ if args.category is not None: # --task handler if args.task is not None: - for i in data.get_tasks(): - if re.match(args.task, i.text, re.IGNORECASE): - data = i + args.task = f".*{args.task}" + data = data.get_task(args.task) # --done handler if args.complete: @@ -72,7 +77,8 @@ if args.info: elif isinstance(data, Task): print("Category: ", data.task_category().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) else: print("Don't know how we ended up here. :/") diff --git a/todo/TodoObject.py b/todo/TodoObject.py index 02c27bf..f99fddb 100644 --- a/todo/TodoObject.py +++ b/todo/TodoObject.py @@ -99,7 +99,7 @@ class TodoObject: parent.children.append(self) 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. Args: @@ -118,7 +118,7 @@ class TodoObject: output.append(child) 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. Args: @@ -129,12 +129,12 @@ class TodoObject: Returns: 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): - 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. Returns: @@ -161,7 +161,7 @@ class TodoObject: Args: immediate (bool, optional): Whether or not it should return immeduate children only. Defaults to False. - +c Returns: Note: Returns all notes found. """ @@ -177,7 +177,7 @@ class TodoObject: Returns: Note: [description] """ - for note in self.get_notes(): + for note in self.get_notes(immediate): if re.match(regex, note.text): return note