Task Options
listr2
can have global or per-task options to change the behavior of how a task or the whole set of tasks in subtask behaves.
Per Listr
Listr task list can be configured how to behave globally by using the second argument of the prototype with given properties.
Per Subtask
This behavior can be further expanded, if the subtask requires a different approach, in this case, these options are generated depending on the current renderer with the given properties.
Naturally, subtasks options are a subset of the general options, since some options are needed to be set only one time, and do not make sense to change per task.
Per Task
Some properties of the task options even propagate to the per-task setting, these are pretty limited in form of configuration but should be just enough for you to not wrap everything in subtasks to change behavior.
Adding Task Options
Task options can be added as follows.
import { Listr, PRESET_TIMER } from 'listr2'
interface Ctx {
/* some variables for internal use */
}
const tasks = new Listr<Ctx>(
[
{
title: 'This task will execute.',
task: (_, task): Listr<Ctx> =>
task.newListr(
[
{
title: 'This task will execute.',
task: async (ctx): Promise<void> => {
// perform some operations
}
},
{
title: 'This task will execute.',
task: async (ctx): Promise<void> => {
// perform some operations
},
exitOnError: false,
rendererOptions: { timer: PRESET_TIMER },
fallbackRendererOptions: { timer: PRESET_TIMER }
}
],
{
concurrent: true,
collectErrors: false,
rendererOptions: { collapseSubtasks: false }
}
)
}
],
{
exitOnError: true,
concurrent: false
}
)
try {
await tasks.run()
} catch (e) {
console.error(e)
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49