Commands:
- add: Add a new task to the to-do list.
- delete: Remove a task from the to-do list by its ID.
- show: List all tasks currently in the to-do list.
- update: Update the task with the specified ID to a new task.
def create_table() -> Nonecreate DB and tasks table
def insert_task(title: str, description: str, priority: int,
due_date: str) -> NoneInsert a new task into the database.
def select_all_tasks() -> listRetrieve all tasks from the database.
Returns:
list of tuples: List of tuples representing all tasks in the database.
def delete_task(task_id: int) -> NoneDelete a task from the database.
Arguments:
task_idint - The ID of the task to be deleted.
def update_task(task_id: int, query, parameters) -> NoneUpdate a task in the database.
Arguments:
task_idint - The ID of the task to be updated.new_titlestr, optional - The new title for the task.new_descriptionstr, optional - The new description for the task.new_priorityint, optional - The new priority for the task.new_due_datestr, optional - The new due date for the task.
def generate_update_query(updates: dict) -> tupleGenerate the SQL update query and parameters based on the provided updates.
Arguments:
updatesdict - Dictionary containing the updates.
Returns:
tuple- Tuple containing the SQL update query and parameters.
@click.group()
@click.version_option(version='0.1', prog_name='Taskmaster')
def main()Taskmaster - Manage your to-do list from the command line.
def validate_due_date(due_date: str) -> boolValidate the due date format.
Arguments:
due_datestr - The due date string.
Returns:
bool- True if the due date format is valid, False otherwise.
@main.command()
@click.option('--title',
'-tl',
prompt=True,
help='Title for the task. [required]')
@click.option('--description',
'-de',
prompt=False,
help='Description for the task. [optional]')
@click.option('--priority',
'-pr',
prompt=True,
default=0,
help='Priority for the task (0 - 5). [required]. default=0')
@click.option('--due_date',
'-dd',
prompt=False,
default=None,
help='Due date for the task. [optional]')
def add(title: str, description: str, priority: int, due_date: str) -> NoneAdd a new task.
This command allows users to add a new task to the to-do list. The user is prompted to enter the title of the task, and optionally, a description, priority, and due date. The task is then added to the list and displayed in a table format, along with the provided information.
Arguments:
titlestr - The title of the task.descriptionstr, optional - The description of the task (optional).priorityint - The priority of the task.due_datestr, optional - The due date of the task (optional).
Example:
taskmaster add-task --title "Finish project" --description "Complete the final report" --priority 1 --due_date "2024-04-10"
@main.command()
def show() -> NoneShow all tasks.
This function retrieves all tasks from the database and displays them in a tabular format.
@main.command()
@click.option('--task_id',
'-id',
prompt=True,
type=int,
help='ID of the task to be deleted. [required]')
def delete(task_id: int) -> NoneDelete a task by its ID.
This command allows users to delete a task from the to-do list by specifying its ID.
Arguments:
task_idint - The ID of the task to be deleted.
@main.command()
@click.option('--task_id',
'-id',
prompt=True,
type=int,
help='ID of the task to be updated.')
@click.option('--new_title',
'-nt',
prompt=False,
help='New title for the task.')
@click.option('--new_description',
'-nd',
prompt=False,
default=None,
help='New description for the task.')
@click.option('--new_priority',
'-np',
prompt=False,
type=int,
help='New priority for the task (0 - 5).')
@click.option('--new_due_date',
'-ndd',
prompt=False,
default=None,
help='New due date for the task.')
def update(task_id: int, new_title: str, new_description: str,
new_priority: int, new_due_date: str) -> NoneUpdate a task.
This command allows users to update a task in the to-do list by specifying its ID. Users can provide new values for the title, description, priority, and due date.
Arguments:
task_idint - The ID of the task to be updated.new_titlestr - The new title for the task.new_descriptionstr, optional - The new description for the task.new_priorityint - The new priority for the task.new_due_datestr, optional - The new due date for the task.