todo task clear command
How about removing all tasks? I.E clearing the project?
The idea is similar to the Implement the clear CLI Command
First, we need to update the Todoer controller:
The next thing is to create the
clear.py file in the
The actual implementation is similar to the original blog post, here we are intentionally using a decorator as a prompt:
from functools import wraps from _todos import todo def _prompt(func_: callable) -> callable: @wraps(func_) def wrapper(project_name: str): while True: choice = input("Delete all to-dos? [y/N]:") if 'y' == choice: return func_(project_name) elif 'N' == choice: print('Operation cancelled') exit(1) print('Invalid choice. Try again') return wrapper @_prompt def clear(project_name: str) -> None: """ Deleting all tasks Args: project_name (str): the project name Return: None """ todo_ = todo.get_todoer(project_name) todo_.remove_all() print("All to-dos were removed")
Get the help of the
As you see, the actual code and also the
DynaCLI implementation did not interfere with the
Let's test our clear command:
DynaCLI just converted
clear function to the CLI
clear command(yes it works with decorated functions).