Conditional Skip
Conditional skip is another way of enabling a Task depending on the given context. But the main difference between enable
and skip
is skip
will always render the given task. When the execution time comes, and it turns out that it should be skipped, it will render or mark it as skipped.
WARNING
Please pay attention to asynchronous operation while designing a context-enabled task list since it does not wait for any variable in the context.
Example
You can find the related examples here.
Usage
Skip call can either have or not have a message, therefore it is optional. Having a message combined with the selected renderer and its settings will yield a different output, where skip message could be directly shown.
Skip inside a Task
import { Listr } from 'listr2'
const tasks = new Listr(
[
{
title: 'This task will execute.',
task: (ctx, task): void => {
task.skip('I am skipping this tasks for reasons.')
}
}
],
{ concurrent: false }
)
await tasks.run()
Skip conditionally defining the Task
import { Listr } from 'listr2'
const tasks = new Listr(
[
{
title: 'This task will execute.',
task: (ctx): void => {
ctx.skip = true
}
},
{
title: 'This task will never execute.',
skip: (ctx): boolean => ctx.skip,
task: (): void => {}
}
],
{ concurrent: false }
)
await tasks.run()
Renderer
DefaultRenderer
The default renderer has options where you can change how the skip messages are displayed.
Details
showSkipMessage?
optional
showSkipMessage:boolean
Show skip messages or show the original title of the task.
true
will output the given skip message if there is any.false
will keep the current task title intact. This will also disablecollapseSkips
.
Default Value
true
Defined in
packages/listr2/src/renderer/default/renderer.interface.ts:88
collapseSkips?
optional
collapseSkips:boolean
Collapse skip messages into a single message and overwrite the task title.
true
will collapse skiped tasks.false
will show the skip message as a data output under the current task title.
Default Value
true
Defined in
packages/listr2/src/renderer/default/renderer.interface.ts:97
suffixSkips?
optional
suffixSkips:boolean
Suffix skip messages to clearly indicate the task has been skipped with in collapseSkips
mode.
true
will add[SKIPPED]
as a suffix.false
will not add a suffix.
Default Value
false
Defined in
packages/listr2/src/renderer/default/renderer.interface.ts:106