Hooks

Hooks can either be specified via the config file or via hook files. But make sure that all hook files are executable, otherwise they won't be picked up by TaskLite.



Stages

Following stages are available:

  • pre-launch - After reading all configs, but before any TaskLite code is executed. Can be used to prevent execution of TaskLite.
  • post-launch - After reading CLI arguments, setting up the database and running all migrations.
  • pre-add - Right before adding a new task. Can be used to prevent addition of task.
  • post-add - After new task was added.
  • pre-modify - Right before a task gets modified. Can be used to prevent modification of task.
  • post-modify - After task was modified.
  • pre-exit - Pre printing results
  • post-exit - Last thing before program termination

The hooks receive data from TaskLite via stdin. Possible fields are:

{
  arguments: […],  // Command line arguments (after `tasklite`)
  taskOriginal: {},  // Task before any modifications by TaskLite
  taskModified: {},  // Modified task
}

After execution, every called hook must print a JSON object to stdout (even if it's empty). All fields of the JSON are optional.

Explanation of possible values:

{
  message: "…",  // A message to display on stdout
  taskModified: "…",  // New version of the task as computed by your script
  tasksToAdd: […],  // Additional tasks to add
}

Hooks can write to stderr at any time, but it is not recommended. Rather write a {message: ''} object to stdout and let TaskLite print the message with improved formatting and coloring.

Legend:

  • ❌ = Not available
  • -> = Must return following object (fields optional) on stdout
Event Input Success
(exitcode == 0)
Error
(exitcode != 0)
pre‑launch
-> {
  message: "…",
}
-> {message: "…"}
Processing terminates
post‑launch
{
  arguments: […]
}
      
{
  message: "…"
}
      
{stderr: "…"}
Processing terminates
pre‑add
{
  arguments: […],
  taskToAdd: {}
}
      
{
  taskToAdd: {},
  message: "…"
}
      
{stderr: "…"}
Processing terminates
post‑add
{
  arguments: […],
  taskAdded: {}
}
      
{
  message: "…"
}
      
{stderr: "…"}
Processing terminates
pre‑modify
{
  arguments: […],
  taskOriginal: {}
}
      
{
  taskModified: {},
  message: "…"
}
      
{stderr: "…"}
Processing terminates
post‑modify
{
  arguments: […],
  taskOriginal: {},
  taskModified: {}
}
      
{
  taskModified: {},
  message: "…"
}
      
{stderr: "…"}
Processing terminates
pre‑exit
{}
      
{
  message: "…"
}
      
{stderr: "…"}
Processing terminates
post‑exit
{}
      
{
  message: "…"
}
      
{stderr: "…"}
Processing terminates

 

To see the JSON for a single task run:

tl ndjson | head -n 1 | jq