Task cleanup with Defer
Learn how to use the Defer feature in Taskfile to ensure cleanup tasks are executed after the main task, even if it fails.
If you have multiple deferred commands, they will run in the reverse order. This means the last deferred command will run first, followed by the second last, and so on. This is useful for tasks that require a specific order of cleanup actions.
You can use the defer
feature in Taskfile to ensure that a cleanup command runs after the main task, regardless of whether the task succeeded or failed. This is particularly useful for tasks that require cleanup actions, such as removing temporary files or directories.
From this example, the rm -rf .cache
command will run after the echo "Installation complete"
command. defer
will always run at the end of the task.