Command-line arguments
Choose how to pass input based on what needs to receive it:
| Input | Example | Read it with |
|---|---|---|
| A Task variable | task greet NAME=Bob | {{.NAME}} |
| Arguments for a command | task yarn -- install | {{.CLI_ARGS}} |
| Part of a task name | task 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:
version: '3'
vars:
NAME: World
tasks:
greet:
cmds:
- echo "Hello, {{.NAME}}!"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:
task build test ENV=productionA 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:
$ task yarn -- installversion: '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:
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:
$ task start:foo
Starting fooYou can use whitespace in your arguments as long as you quote the task name:
$ task "start:foo bar"
Starting foo barIf 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.
$ task start:foo:3
Starting foo with 3 replicasWildcard task names also work with aliases:
version: '3'
tasks:
start:*:
aliases: [run:*]
vars:
SERVICE: '{{index .MATCH 0}}'
cmds:
- echo "Running {{.SERVICE}}"Call the task through the run:* alias:
$ task run:foo
Running foo