Skip to content

Command-line arguments ​

Choose how to pass input based on what needs to receive it:

InputExampleRead it with
A Task variabletask greet NAME=Bob{{.NAME}}
Arguments for a commandtask yarn -- install{{.CLI_ARGS}}
Part of a task nametask start:api{{index .MATCH 0}}

Pass named values ​

Pass NAME=value to supply a Task variable. A default in the root vars block can be overridden from the command line:

yaml
version: '3'

vars:
  NAME: World

tasks:
  greet:
    cmds:
      - echo "Hello, {{.NAME}}!"
shell
task greet NAME=Bob
task greet "NAME=Jane Doe"

Quote assignments that contain spaces. These assignments work across shells, including Windows, and are shared by all tasks in the invocation:

shell
task build test ENV=production

A value declared in a task's own vars can override the command-line value. See variable resolution for precedence and configurable defaults. To set values in a command's shell environment, see Environment variables.

Forward command arguments ​

Everything after -- is available in .CLI_ARGS, including values containing =. Insert it into a command to forward those arguments. This example runs yarn install:

shell
$ task yarn -- install
yaml
version: '3'

tasks:
  yarn:
    cmds:
      - yarn {{.CLI_ARGS}}

Capture task-name inputs ​

Use * in a task name to turn a call such as task start:api into an input. Task captures each wildcard in the .MATCH array. Give the captured values names with vars so their meaning stays clear:

yaml
version: '3'

tasks:
  start:*:*:
    vars:
      SERVICE: '{{index .MATCH 0}}'
      REPLICAS: '{{index .MATCH 1}}'
    cmds:
      - echo "Starting {{.SERVICE}} with {{.REPLICAS}} replicas"

  start:*:
    vars:
      SERVICE: '{{index .MATCH 0}}'
    cmds:
      - echo "Starting {{.SERVICE}}"

The first captured value becomes SERVICE:

shell
$ task start:foo
Starting foo

You can use whitespace in your arguments as long as you quote the task name:

shell
$ task "start:foo bar"
Starting foo bar

If multiple matching tasks are found, the first one listed in the Taskfile will be used. If you are using included Taskfiles, tasks in parent files will be considered first.

shell
$ task start:foo:3
Starting foo with 3 replicas

Wildcard task names also work with aliases:

yaml
version: '3'

tasks:
  start:*:
    aliases: [run:*]
    vars:
      SERVICE: '{{index .MATCH 0}}'
    cmds:
      - echo "Running {{.SERVICE}}"

Call the task through the run:* alias:

shell
$ task run:foo
Running foo