Skipping a Task

Introduction

Skip is another way of enabling a task depending on the given context. But the main difference with enable is it will always render the given task. When the execution time comes and it turns out that it should be skipped, it will render it as skipped.

Please pay attention to asynchronous operation while designing a context-enabled task list since it does not wait for any variable in the context.

Usage

Please refer to examples section for more detailed and further examples.

Skip a task inside the task itself after some logic is done

new Listr<Ctx>(
  [
    {
      title: 'This task will execute.',
      task: (ctx, task): void => {
        task.skip('I am skipping this tasks for reasons.')
      }
    }
  ],
  { concurrent: false }
)

Skip a task through the task wrapper

new Listr<Ctx>(
  [
    {
      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 }
)

Renderer

Default Renderer

/**
 * show skip messages or show the original title of the task, this will also disable collapseSkips mode
 *
 * You can disable showing the skip messages, even though you passed in a message by settings this option,
 * if you want to keep the original task title intact.
 *
 * @default true
 */
showSkipMessage?: boolean
/**
 * collapse skip messages into a single message and overwrite the task title
 *
 * @default true
 */
collapseSkips?: boolean
/**
 * suffix skip messages with [SKIPPED] when in collapseSkips mode
 *
 * @default true
 */
suffixSkips?: boolean
Edit this page on GitHub Updated at Tue, Feb 1, 2022