1
0
mirror of https://github.com/go-task/task.git synced 2024-12-12 10:45:49 +02:00

chore: sync translations (#1280)

This commit is contained in:
task-bot 2023-07-26 09:51:01 -03:00 committed by GitHub
parent 44ca1fc77e
commit 7bcdccc645
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 1425 additions and 165 deletions

View File

@ -120,12 +120,13 @@ There are some special variables that is available on the templating system:
| `TASKFILE_DIR` | The absolute path of the included Taskfile. | | `TASKFILE_DIR` | The absolute path of the included Taskfile. |
| `USER_WORKING_DIR` | The absolute path of the directory `task` was called from. | | `USER_WORKING_DIR` | The absolute path of the directory `task` was called from. |
| `CHECKSUM` | The checksum of the files listed in `sources`. Only available within the `status` prop and if method is set to `checksum`. | | `CHECKSUM` | The checksum of the files listed in `sources`. Only available within the `status` prop and if method is set to `checksum`. |
| `TIMESTAMP` | The date object of the greatest timestamp of the files listes in `sources`. Only available within the `status` prop and if method is set to `timestamp`. | | `TIMESTAMP` | The date object of the greatest timestamp of the files listed in `sources`. Only available within the `status` prop and if method is set to `timestamp`. |
| `TASK_VERSION` | The current version of task. | | `TASK_VERSION` | The current version of task. |
| `ITEM` | The value of the current iteration when using the `for` property. |
## ENV ## ENV
Some environment variables can be overriden to adjust Task behavior. Some environment variables can be overridden to adjust Task behavior.
| ENV | Default | Description | | ENV | Default | Description |
| -------------------- | ------- | ----------------------------------------------------------------------------------------------------------------- | | -------------------- | ------- | ----------------------------------------------------------------------------------------------------------------- |
@ -254,8 +255,9 @@ tasks:
| Attribute | Type | Default | Description | | Attribute | Type | Default | Description |
| -------------- | ---------------------------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | -------------- | ---------------------------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `cmd` | `string` | | The shell command to be executed. | | `cmd` | `string` | | The shell command to be executed. |
| `silent` | `bool` | `false` | Skips some output for this command. Note that STDOUT and STDERR of the commands will still be redirected. |
| `task` | `string` | | Set this to trigger execution of another task instead of running a command. This cannot be set together with `cmd`. | | `task` | `string` | | Set this to trigger execution of another task instead of running a command. This cannot be set together with `cmd`. |
| `for` | [`For`](#for) | | Runs the command once for each given value. |
| `silent` | `bool` | `false` | Skips some output for this command. Note that STDOUT and STDERR of the commands will still be redirected. |
| `vars` | [`map[string]Variable`](#variable) | | Optional additional variables to be passed to the referenced task. Only relevant when setting `task` instead of `cmd`. | | `vars` | [`map[string]Variable`](#variable) | | Optional additional variables to be passed to the referenced task. Only relevant when setting `task` instead of `cmd`. |
| `ignore_error` | `bool` | `false` | Continue execution if errors happen while executing the command. | | `ignore_error` | `bool` | `false` | Continue execution if errors happen while executing the command. |
| `defer` | `string` | | Alternative to `cmd`, but schedules the command to be executed at the end of this task instead of immediately. This cannot be used together with `cmd`. | | `defer` | `string` | | Alternative to `cmd`, but schedules the command to be executed at the end of this task instead of immediately. This cannot be used together with `cmd`. |
@ -297,6 +299,22 @@ tasks:
::: :::
#### For
The `for` parameter can be defined as a string, a list of strings or a map. If it is defined as a string, you can give it any of the following values:
- `source` - Will run the command for each source file defined on the task. (Glob patterns will be resolved, so `*.go` will run for every Go file that matches).
If it is defined as a list of strings, the command will be run for each value.
Finally, the `for` parameter can be defined as a map when you want to use a variable to define the values to loop over:
| Attribute | Type | Default | Description |
| --------- | -------- | ---------------- | -------------------------------------------- |
| `var` | `string` | | The name of the variable to use as an input. |
| `split` | `string` | (any whitespace) | What string the variable should be split on. |
| `as` | `string` | `ITEM` | The name of the iterator variable. |
#### Precondition #### Precondition
| Attribute | Type | Default | Description | | Attribute | Type | Default | Description |

View File

@ -9,7 +9,7 @@ sidebar_position: 6
Task has an [official extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=task.vscode-task). El código de ese proyecto puede ser encontrado [aquí](https://github.com/go-task/vscode-task). Para usar la extensión es necesario tener instalada la versión v3.23.0+ de Task. Task has an [official extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=task.vscode-task). El código de ese proyecto puede ser encontrado [aquí](https://github.com/go-task/vscode-task). Para usar la extensión es necesario tener instalada la versión v3.23.0+ de Task.
This extension provides the following features (and more): La extensión proporciona las siguientes funcionalidades (y más...):
- View tasks in the sidebar. - View tasks in the sidebar.
- Ejecuta tareas desde la barra lateral y la paleta de comandos. - Ejecuta tareas desde la barra lateral y la paleta de comandos.

View File

@ -863,6 +863,168 @@ tasks:
This works for all types of variables. This works for all types of variables.
## Looping over values
Task allows you to loop over certain values and execute a command for each. There are a number of ways to do this depending on the type of value you want to loop over.
### Looping over a static list
The simplest kind of loop is an explicit one. This is useful when you want to loop over a set of values that are known ahead of time.
```yaml
version: '3'
tasks:
default:
cmds:
- for: ['foo.txt', 'bar.txt']
cmd: cat {{ .ITEM }}
```
### Looping over your task's sources
You are also able to loop over the sources of your task:
```yaml
version: '3'
tasks:
default:
sources:
- foo.txt
- bar.txt
cmds:
- for: sources
cmd: cat {{ .ITEM }}
```
This will also work if you use globbing syntax in your sources. For example, if you specify a source for `*.txt`, the loop will iterate over all files that match that glob.
Source paths will always be returned as paths relative to the task directory. If you need to convert this to an absolute path, you can use the built-in `joinPath` function:
```yaml
version: '3'
tasks:
default:
vars:
MY_DIR: /path/to/dir
dir: '{{.MY_DIR}}'
sources:
- foo.txt
- bar.txt
cmds:
- for: sources
cmd: cat {{ joinPath .MY_DIR .ITEM }}
```
### Looping over variables
To loop over the contents of a variable, you simply need to specify the variable you want to loop over. By default, variables will be split on any whitespace characters.
```yaml
version: '3'
tasks:
default:
vars:
my_var: foo.txt bar.txt
cmds:
- for:
var: my_var
cmd: cat {{ .ITEM }}
```
If you need to split on a different character, you can do this by specifying the `split` property:
```yaml
version: '3'
tasks:
default:
vars:
my_var: foo.txt,bar.txt
cmds:
- for:
var: my_var
split: ','
cmd: cat {{ .ITEM }}
```
All of this also works with dynamic variables!
```yaml
version: '3'
tasks:
default:
vars:
my_var:
sh: find -type f -name '*.txt'
cmds:
- for:
var: my_var
cmd: cat {{ .ITEM }}
```
### Renaming variables
If you want to rename the iterator variable to make it clearer what the value contains, you can do so by specifying the `as` property:
```yaml
version: '3'
tasks:
default:
vars:
my_var: foo.txt bar.txt
cmds:
- for:
var: my_var
as: FILE
cmd: cat {{ .FILE }}
```
### Looping over tasks
Because the `for` property is defined at the `cmds` level, you can also use it alongside the `task` keyword to run tasks multiple times with different variables.
```yaml
version: '3'
tasks:
default:
cmds:
- for: [foo, bar]
task: my-task
vars:
FILE: '{{ .ITEM }}'
my-task:
cmds:
- echo '{{ .FILE }}'
```
Or if you want to run different tasks depending on the value of the loop:
```yaml
version: '3'
tasks:
default:
cmds:
- for: [foo, bar]
task: task-{{ .ITEM }}
task-foo:
cmds:
- echo 'foo'
task-bar:
cmds:
- echo 'bar'
```
## Forwarding CLI arguments to commands ## Forwarding CLI arguments to commands
If `--` is given in the CLI, all following parameters are added to a special `.CLI_ARGS` variable. This is useful to forward arguments to another command. If `--` is given in the CLI, all following parameters are added to a special `.CLI_ARGS` variable. This is useful to forward arguments to another command.

View File

@ -120,12 +120,13 @@ There are some special variables that is available on the templating system:
| `TASKFILE_DIR` | The absolute path of the included Taskfile. | | `TASKFILE_DIR` | The absolute path of the included Taskfile. |
| `USER_WORKING_DIR` | The absolute path of the directory `task` was called from. | | `USER_WORKING_DIR` | The absolute path of the directory `task` was called from. |
| `CHECKSUM` | The checksum of the files listed in `sources`. Only available within the `status` prop and if method is set to `checksum`. | | `CHECKSUM` | The checksum of the files listed in `sources`. Only available within the `status` prop and if method is set to `checksum`. |
| `TIMESTAMP` | The date object of the greatest timestamp of the files listes in `sources`. Only available within the `status` prop and if method is set to `timestamp`. | | `TIMESTAMP` | The date object of the greatest timestamp of the files listed in `sources`. Only available within the `status` prop and if method is set to `timestamp`. |
| `TASK_VERSION` | The current version of task. | | `TASK_VERSION` | The current version of task. |
| `ITEM` | The value of the current iteration when using the `for` property. |
## ENV ## ENV
Some environment variables can be overriden to adjust Task behavior. Some environment variables can be overridden to adjust Task behavior.
| ENV | Default | Description | | ENV | Default | Description |
| -------------------- | ------- | ----------------------------------------------------------------------------------------------------------------- | | -------------------- | ------- | ----------------------------------------------------------------------------------------------------------------- |
@ -254,8 +255,9 @@ tasks:
| Attribute | Type | Default | Description | | Attribute | Type | Default | Description |
| -------------- | ---------------------------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | -------------- | ---------------------------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `cmd` | `string` | | The shell command to be executed. | | `cmd` | `string` | | The shell command to be executed. |
| `silent` | `bool` | `false` | Skips some output for this command. Note that STDOUT and STDERR of the commands will still be redirected. |
| `task` | `string` | | Set this to trigger execution of another task instead of running a command. This cannot be set together with `cmd`. | | `task` | `string` | | Set this to trigger execution of another task instead of running a command. This cannot be set together with `cmd`. |
| `for` | [`For`](#for) | | Runs the command once for each given value. |
| `silent` | `bool` | `false` | Skips some output for this command. Note that STDOUT and STDERR of the commands will still be redirected. |
| `vars` | [`map[string]Variable`](#variable) | | Optional additional variables to be passed to the referenced task. Only relevant when setting `task` instead of `cmd`. | | `vars` | [`map[string]Variable`](#variable) | | Optional additional variables to be passed to the referenced task. Only relevant when setting `task` instead of `cmd`. |
| `ignore_error` | `bool` | `false` | Continue execution if errors happen while executing the command. | | `ignore_error` | `bool` | `false` | Continue execution if errors happen while executing the command. |
| `defer` | `string` | | Alternative to `cmd`, but schedules the command to be executed at the end of this task instead of immediately. This cannot be used together with `cmd`. | | `defer` | `string` | | Alternative to `cmd`, but schedules the command to be executed at the end of this task instead of immediately. This cannot be used together with `cmd`. |
@ -297,6 +299,22 @@ tasks:
::: :::
#### For
The `for` parameter can be defined as a string, a list of strings or a map. If it is defined as a string, you can give it any of the following values:
- `source` - Will run the command for each source file defined on the task. (Glob patterns will be resolved, so `*.go` will run for every Go file that matches).
If it is defined as a list of strings, the command will be run for each value.
Finally, the `for` parameter can be defined as a map when you want to use a variable to define the values to loop over:
| Attribute | Type | Default | Description |
| --------- | -------- | ---------------- | -------------------------------------------- |
| `var` | `string` | | The name of the variable to use as an input. |
| `split` | `string` | (any whitespace) | What string the variable should be split on. |
| `as` | `string` | `ITEM` | The name of the iterator variable. |
#### Precondition #### Precondition
| Attribute | Type | Default | Description | | Attribute | Type | Default | Description |

View File

@ -863,6 +863,168 @@ tasks:
This works for all types of variables. This works for all types of variables.
## Looping over values
Task allows you to loop over certain values and execute a command for each. There are a number of ways to do this depending on the type of value you want to loop over.
### Looping over a static list
The simplest kind of loop is an explicit one. This is useful when you want to loop over a set of values that are known ahead of time.
```yaml
version: '3'
tasks:
default:
cmds:
- for: ['foo.txt', 'bar.txt']
cmd: cat {{ .ITEM }}
```
### Looping over your task's sources
You are also able to loop over the sources of your task:
```yaml
version: '3'
tasks:
default:
sources:
- foo.txt
- bar.txt
cmds:
- for: sources
cmd: cat {{ .ITEM }}
```
This will also work if you use globbing syntax in your sources. For example, if you specify a source for `*.txt`, the loop will iterate over all files that match that glob.
Source paths will always be returned as paths relative to the task directory. If you need to convert this to an absolute path, you can use the built-in `joinPath` function:
```yaml
version: '3'
tasks:
default:
vars:
MY_DIR: /path/to/dir
dir: '{{.MY_DIR}}'
sources:
- foo.txt
- bar.txt
cmds:
- for: sources
cmd: cat {{ joinPath .MY_DIR .ITEM }}
```
### Looping over variables
To loop over the contents of a variable, you simply need to specify the variable you want to loop over. By default, variables will be split on any whitespace characters.
```yaml
version: '3'
tasks:
default:
vars:
my_var: foo.txt bar.txt
cmds:
- for:
var: my_var
cmd: cat {{ .ITEM }}
```
If you need to split on a different character, you can do this by specifying the `split` property:
```yaml
version: '3'
tasks:
default:
vars:
my_var: foo.txt,bar.txt
cmds:
- for:
var: my_var
split: ','
cmd: cat {{ .ITEM }}
```
All of this also works with dynamic variables!
```yaml
version: '3'
tasks:
default:
vars:
my_var:
sh: find -type f -name '*.txt'
cmds:
- for:
var: my_var
cmd: cat {{ .ITEM }}
```
### Renaming variables
If you want to rename the iterator variable to make it clearer what the value contains, you can do so by specifying the `as` property:
```yaml
version: '3'
tasks:
default:
vars:
my_var: foo.txt bar.txt
cmds:
- for:
var: my_var
as: FILE
cmd: cat {{ .FILE }}
```
### Looping over tasks
Because the `for` property is defined at the `cmds` level, you can also use it alongside the `task` keyword to run tasks multiple times with different variables.
```yaml
version: '3'
tasks:
default:
cmds:
- for: [foo, bar]
task: my-task
vars:
FILE: '{{ .ITEM }}'
my-task:
cmds:
- echo '{{ .FILE }}'
```
Or if you want to run different tasks depending on the value of the loop:
```yaml
version: '3'
tasks:
default:
cmds:
- for: [foo, bar]
task: task-{{ .ITEM }}
task-foo:
cmds:
- echo 'foo'
task-bar:
cmds:
- echo 'bar'
```
## Forwarding CLI arguments to commands ## Forwarding CLI arguments to commands
If `--` is given in the CLI, all following parameters are added to a special `.CLI_ARGS` variable. This is useful to forward arguments to another command. If `--` is given in the CLI, all following parameters are added to a special `.CLI_ARGS` variable. This is useful to forward arguments to another command.

View File

@ -1,54 +1,54 @@
{ {
"theme.ErrorPageContent.title": { "theme.ErrorPageContent.title": {
"message": "This page crashed.", "message": "ページがクラッシュしました。",
"description": "The title of the fallback page when the page crashed" "description": "The title of the fallback page when the page crashed"
}, },
"theme.ErrorPageContent.tryAgain": { "theme.ErrorPageContent.tryAgain": {
"message": "Try again", "message": "もう一度お試しください",
"description": "The label of the button to try again when the page crashed" "description": "The label of the button to try again when the page crashed"
}, },
"theme.NotFound.title": { "theme.NotFound.title": {
"message": "Page Not Found", "message": "ページが見つかりませんでした",
"description": "The title of the 404 page" "description": "The title of the 404 page"
}, },
"theme.NotFound.p1": { "theme.NotFound.p1": {
"message": "We could not find what you were looking for.", "message": "お探しのページが見つかりませんでした。",
"description": "The first paragraph of the 404 page" "description": "The first paragraph of the 404 page"
}, },
"theme.NotFound.p2": { "theme.NotFound.p2": {
"message": "Please contact the owner of the site that linked you to the original URL and let them know their link is broken.", "message": "アクセスを試みたのURLをリンクしたサイトの管理者に連絡して、そのリンクが壊れていることを知らせてください。",
"description": "The 2nd paragraph of the 404 page" "description": "The 2nd paragraph of the 404 page"
}, },
"theme.admonition.note": { "theme.admonition.note": {
"message": "note", "message": "メモ",
"description": "The default label used for the Note admonition (:::note)" "description": "The default label used for the Note admonition (:::note)"
}, },
"theme.admonition.tip": { "theme.admonition.tip": {
"message": "tip", "message": "ヒント",
"description": "The default label used for the Tip admonition (:::tip)" "description": "The default label used for the Tip admonition (:::tip)"
}, },
"theme.admonition.danger": { "theme.admonition.danger": {
"message": "danger", "message": "危険",
"description": "The default label used for the Danger admonition (:::danger)" "description": "The default label used for the Danger admonition (:::danger)"
}, },
"theme.admonition.info": { "theme.admonition.info": {
"message": "info", "message": "お知らせ",
"description": "The default label used for the Info admonition (:::info)" "description": "The default label used for the Info admonition (:::info)"
}, },
"theme.admonition.caution": { "theme.admonition.caution": {
"message": "caution", "message": "注意",
"description": "The default label used for the Caution admonition (:::caution)" "description": "The default label used for the Caution admonition (:::caution)"
}, },
"theme.BackToTopButton.buttonAriaLabel": { "theme.BackToTopButton.buttonAriaLabel": {
"message": "Scroll back to top", "message": "ページ上部へ戻る",
"description": "The ARIA label for the back to top button" "description": "The ARIA label for the back to top button"
}, },
"theme.blog.archive.title": { "theme.blog.archive.title": {
"message": "Archive", "message": "アーカイブ",
"description": "The page & hero title of the blog archive page" "description": "The page & hero title of the blog archive page"
}, },
"theme.blog.archive.description": { "theme.blog.archive.description": {
"message": "Archive", "message": "アーカイブ",
"description": "The page & hero description of the blog archive page" "description": "The page & hero description of the blog archive page"
}, },
"theme.blog.paginator.navAriaLabel": { "theme.blog.paginator.navAriaLabel": {
@ -195,7 +195,7 @@
"description": "The ARIA label for copy code blocks button" "description": "The ARIA label for copy code blocks button"
}, },
"theme.CodeBlock.copy": { "theme.CodeBlock.copy": {
"message": "Copy", "message": "コピー",
"description": "The copy button label on code blocks" "description": "The copy button label on code blocks"
}, },
"theme.CodeBlock.wordWrapToggle": { "theme.CodeBlock.wordWrapToggle": {

View File

@ -1,6 +1,6 @@
{ {
"version.label": { "version.label": {
"message": "Next", "message": "次へ",
"description": "The label for version current" "description": "The label for version current"
} }
} }

View File

@ -5,11 +5,11 @@ toc_min_heading_level: 2
toc_max_heading_level: 5 toc_max_heading_level: 5
--- ---
# API Reference # APIリファレンス
## CLI ## CLI
Task command line tool has the following syntax: Taskコマンドラインツールは以下のような構文を持っています:
```bash ```bash
task [--flags] [tasks...] [-- CLI_ARGS...] task [--flags] [tasks...] [-- CLI_ARGS...]
@ -17,15 +17,15 @@ task [--flags] [tasks...] [-- CLI_ARGS...]
:::tip :::tip
If `--` is given, all remaning arguments will be assigned to a special `CLI_ARGS` variable `--`が指定された場合、それ以降のすべての引数は特殊な`CLI_ARGS`変数に格納されます
::: :::
| Short | Flag | Type | Default | Description | | ショート | フラグ | 型 | デフォルト値 | 説明 |
| ----- | --------------------------- | -------- | -------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ---- | --------------------------- | -------- | -------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `-c` | `--color` | `bool` | `true` | Colored output. Enabled by default. Set flag to `false` or use `NO_COLOR=1` to disable. | | `-c` | `--color` | `bool` | `true` | Colored output. Enabled by default. Set flag to `false` or use `NO_COLOR=1` to disable. |
| `-C` | `--concurrency` | `int` | `0` | Limit number tasks to run concurrently. Zero means unlimited. | | `-C` | `--concurrency` | `int` | `0` | Limit number tasks to run concurrently. Zero means unlimited. |
| `-d` | `--dir` | `string` | Working directory | Sets directory of execution. | | `-d` | `--dir` | `string` | ワーキングディレクトリ | Sets directory of execution. |
| `-n` | `--dry` | `bool` | `false` | Compiles and prints tasks in the order that they would be run, without executing them. | | `-n` | `--dry` | `bool` | `false` | Compiles and prints tasks in the order that they would be run, without executing them. |
| `-x` | `--exit-code` | `bool` | `false` | Pass-through the exit code of the task command. | | `-x` | `--exit-code` | `bool` | `false` | Pass-through the exit code of the task command. |
| `-f` | `--force` | `bool` | `false` | Forces execution even when the task is up-to-date. | | `-f` | `--force` | `bool` | `false` | Forces execution even when the task is up-to-date. |
@ -46,12 +46,12 @@ If `--` is given, all remaning arguments will be assigned to a special `CLI_ARGS
| `-y` | `--yes` | `bool` | `false` | Assume "yes" as answer to all prompts. | | `-y` | `--yes` | `bool` | `false` | Assume "yes" as answer to all prompts. |
| | `--status` | `bool` | `false` | Exits with non-zero exit code if any of the given tasks is not up-to-date. | | | `--status` | `bool` | `false` | Exits with non-zero exit code if any of the given tasks is not up-to-date. |
| | `--summary` | `bool` | `false` | Show summary about a task. | | | `--summary` | `bool` | `false` | Show summary about a task. |
| `-t` | `--taskfile` | `string` | `Taskfile.yml` or `Taskfile.yaml` | | | `-t` | `--taskfile` | `string` | `Taskfile.yml`または`Taskfile.yaml` | |
| `-v` | `--verbose` | `bool` | `false` | Enables verbose mode. | | `-v` | `--verbose` | `bool` | `false` | Enables verbose mode. |
| | `--version` | `bool` | `false` | Show Task version. | | | `--version` | `bool` | `false` | Show Task version. |
| `-w` | `--watch` | `bool` | `false` | Enables watch of the given task. | | `-w` | `--watch` | `bool` | `false` | Enables watch of the given task. |
## Exit Codes ## 終了コード
Task will sometimes exit with specific exit codes. These codes are split into three groups with the following ranges: Task will sometimes exit with specific exit codes. These codes are split into three groups with the following ranges:
@ -84,7 +84,7 @@ When Task is run with the `-x`/`--exit-code` flag, the exit code of any failed c
::: :::
## JSON Output ## JSON出力
When using the `--json` flag in combination with either the `--list` or `--list-all` flags, the output will be a JSON object with the following structure: When using the `--json` flag in combination with either the `--list` or `--list-all` flags, the output will be a JSON object with the following structure:
@ -108,7 +108,7 @@ When using the `--json` flag in combination with either the `--list` or `--list-
} }
``` ```
## Special Variables ## 特殊な変数
There are some special variables that is available on the templating system: There are some special variables that is available on the templating system:
@ -120,12 +120,13 @@ There are some special variables that is available on the templating system:
| `TASKFILE_DIR` | The absolute path of the included Taskfile. | | `TASKFILE_DIR` | The absolute path of the included Taskfile. |
| `USER_WORKING_DIR` | The absolute path of the directory `task` was called from. | | `USER_WORKING_DIR` | The absolute path of the directory `task` was called from. |
| `CHECKSUM` | The checksum of the files listed in `sources`. Only available within the `status` prop and if method is set to `checksum`. | | `CHECKSUM` | The checksum of the files listed in `sources`. Only available within the `status` prop and if method is set to `checksum`. |
| `TIMESTAMP` | The date object of the greatest timestamp of the files listes in `sources`. Only available within the `status` prop and if method is set to `timestamp`. | | `TIMESTAMP` | The date object of the greatest timestamp of the files listed in `sources`. Only available within the `status` prop and if method is set to `timestamp`. |
| `TASK_VERSION` | The current version of task. | | `TASK_VERSION` | The current version of task. |
| `ITEM` | The value of the current iteration when using the `for` property. |
## ENV ## ENV
Some environment variables can be overriden to adjust Task behavior. Some environment variables can be overridden to adjust Task behavior.
| ENV | Default | Description | | ENV | Default | Description |
| -------------------- | ------- | ----------------------------------------------------------------------------------------------------------------- | | -------------------- | ------- | ----------------------------------------------------------------------------------------------------------------- |
@ -254,8 +255,9 @@ tasks:
| Attribute | Type | Default | Description | | Attribute | Type | Default | Description |
| -------------- | ---------------------------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | -------------- | ---------------------------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `cmd` | `string` | | The shell command to be executed. | | `cmd` | `string` | | The shell command to be executed. |
| `silent` | `bool` | `false` | Skips some output for this command. Note that STDOUT and STDERR of the commands will still be redirected. |
| `task` | `string` | | Set this to trigger execution of another task instead of running a command. This cannot be set together with `cmd`. | | `task` | `string` | | Set this to trigger execution of another task instead of running a command. This cannot be set together with `cmd`. |
| `for` | [`For`](#for) | | Runs the command once for each given value. |
| `silent` | `bool` | `false` | Skips some output for this command. Note that STDOUT and STDERR of the commands will still be redirected. |
| `vars` | [`map[string]Variable`](#variable) | | Optional additional variables to be passed to the referenced task. Only relevant when setting `task` instead of `cmd`. | | `vars` | [`map[string]Variable`](#variable) | | Optional additional variables to be passed to the referenced task. Only relevant when setting `task` instead of `cmd`. |
| `ignore_error` | `bool` | `false` | Continue execution if errors happen while executing the command. | | `ignore_error` | `bool` | `false` | Continue execution if errors happen while executing the command. |
| `defer` | `string` | | Alternative to `cmd`, but schedules the command to be executed at the end of this task instead of immediately. This cannot be used together with `cmd`. | | `defer` | `string` | | Alternative to `cmd`, but schedules the command to be executed at the end of this task instead of immediately. This cannot be used together with `cmd`. |
@ -297,6 +299,22 @@ tasks:
::: :::
#### For
The `for` parameter can be defined as a string, a list of strings or a map. If it is defined as a string, you can give it any of the following values:
- `source` - Will run the command for each source file defined on the task. (Glob patterns will be resolved, so `*.go` will run for every Go file that matches).
If it is defined as a list of strings, the command will be run for each value.
Finally, the `for` parameter can be defined as a map when you want to use a variable to define the values to loop over:
| Attribute | Type | Default | Description |
| --------- | -------- | ---------------- | -------------------------------------------- |
| `var` | `string` | | The name of the variable to use as an input. |
| `split` | `string` | (any whitespace) | What string the variable should be split on. |
| `as` | `string` | `ITEM` | The name of the iterator variable. |
#### Precondition #### Precondition
| Attribute | Type | Default | Description | | Attribute | Type | Default | Description |

View File

@ -9,7 +9,7 @@ sidebar_position: 8
これには一般的なガイドラインが含まれていますが、必ずしも厳密に従う必要はありません。 必要であったり、あるいは違う方法を取りたい場合は自由にしてください。 また、このガイドの改善点について、IssueまたはPull Requestを開くことも自由です。 これには一般的なガイドラインが含まれていますが、必ずしも厳密に従う必要はありません。 必要であったり、あるいは違う方法を取りたい場合は自由にしてください。 また、このガイドの改善点について、IssueまたはPull Requestを開くことも自由です。
## `taskfile.yml`ではなく`Taskfile.yml`を使用してください ## `taskfile.yml`ではなく`Taskfile.yml`を使用する
```yaml ```yaml
# bad # bad
@ -22,16 +22,16 @@ Taskfile.yml
これはLinuxユーザーにとって特に重要です。 WindowsとmacOSは大文字と小文字を区別しないファイルシステム持っているので、公式にはサポートされていないにもかかわらず、`taskfile.yml`は正常に動作します。 Linuxでは`Taskfile.yml`だけが動作します。 これはLinuxユーザーにとって特に重要です。 WindowsとmacOSは大文字と小文字を区別しないファイルシステム持っているので、公式にはサポートされていないにもかかわらず、`taskfile.yml`は正常に動作します。 Linuxでは`Taskfile.yml`だけが動作します。
## Use the correct order of keywords ## キーワードを正しい順序にする
- `version:` - `version:`
- `includes:` - `includes:`
- Configuration ones, like `output:`, `silent:`, `method:` and `run:` - 設定項目として、`output:`、`silent:`、`method:`、そして`run:`があります。
- `vars:` - `vars:`
- `env:`, `dotenv:` - `env:`, `dotenv:`
- `tasks:` - `tasks:`
## インデントにはスペース2つを使用してください ## インデントにはスペース2つを使用する
これはYAMLファイルの最も一般的な慣習であり、Taskはそれに倣うものです。 これはYAMLファイルの最も一般的な慣習であり、Taskはそれに倣うものです。
@ -50,7 +50,7 @@ tasks:
- echo 'foo' - echo 'foo'
``` ```
## Separate with spaces the mains sections ## メインセクションをスペースで分ける
```yaml ```yaml
# bad # bad
@ -84,7 +84,7 @@ tasks:
# ... # ...
``` ```
## Add spaces between tasks ## タスク間にスペースを設ける
```yaml ```yaml
# bad # bad
@ -119,7 +119,7 @@ tasks:
- echo 'baz' - echo 'baz'
``` ```
## Use upper-case variable names ## 変数名は大文字で定義する
```yaml ```yaml
# bad # bad
@ -146,7 +146,7 @@ tasks:
- go build -o {{.BINARY_NAME}} . - go build -o {{.BINARY_NAME}} .
``` ```
## Don't wrap vars in spaces when templating ## テンプレート記法で変数名の前後に空白を設けない
```yaml ```yaml
# bad # bad
@ -167,9 +167,9 @@ tasks:
- echo '{{.MESSAGE}}' - echo '{{.MESSAGE}}'
``` ```
This convention is also used by most people for any Go templating. この書き方は多くの人によってGoのテンプレート作成にも使われています。
## Separate task name words with a dash ## タスク名の単語をハイフンで区切る
```yaml ```yaml
# bad # bad
@ -190,7 +190,7 @@ tasks:
- echo 'Do something' - echo 'Do something'
``` ```
## Use colon for task namespacing ## タスクの名前空間にコロンを使用する
```yaml ```yaml
# good # good
@ -206,9 +206,9 @@ tasks:
- docker-compose ... - docker-compose ...
``` ```
This is also done automatically when using included Taskfiles. これはインクルードされたタスクファイルを使用する場合に、自動的に行われます。
## Prefer external scripts over complex multi-line commands ## 複雑な複数行のコマンドの使用は避け、外部スクリプトを使用する
```yaml ```yaml
# bad # bad

View File

@ -71,13 +71,13 @@ tasks:
`--global` (エイリアス `-g`) フラグと一緒にTaskを実行すると、ワーキングディレクトリの代わりにホームディレクトリからTaskfileを探します。 つまり、Taskは`$HOME/{T,t}askfile.{yml,yaml}`にマッチするファイルを探します。 `--global` (エイリアス `-g`) フラグと一緒にTaskを実行すると、ワーキングディレクトリの代わりにホームディレクトリからTaskfileを探します。 つまり、Taskは`$HOME/{T,t}askfile.{yml,yaml}`にマッチするファイルを探します。
This is useful to have automation that you can run from anywhere in your system! これはシステム内のどこからでも自動化処理を実行可能にする便利な機能です!
:::info :::info
When running your global Taskfile with `-g`, tasks will run on `$HOME` by default, and not on your working directory! グローバルなTaskfileを`-g`で実行するとき、タスクはワーキンクディレクトリではなく、デフォルトでは`$HOME`ディレクトリで実行されます!
As mentioned in the previous section, the `{{.USER_WORKING_DIR}}` special variable can be very handy here to run stuff on the directory you're calling `task -g` from. 前述したように、`{{.USER_WORKING_DIR}}`という特別な変数は非常に便利で、`task -g`を呼び出しているディレクトリで実行させることができます。
```yaml ```yaml
version: '3' version: '3'
@ -128,13 +128,13 @@ tasks:
:::info :::info
`env` supports expansion and retrieving output from a shell command just like variables, as you can see in the [Variables](#variables) section. `env`は変数と同様に、シェルコマンドからの出力を取得して展開することが可能です。詳細は[変数](#variables)セクションを参照してください。
::: :::
### .envファイル ### .envファイル
You can also ask Task to include `.env` like files by using the `dotenv:` setting: `dotenv:`設定を使用してTaskに`.env`のようなファイルを読み込ませることもできます:
```bash title=".env" ```bash title=".env"
KEYNAME=VALUE KEYNAME=VALUE
@ -158,7 +158,7 @@ tasks:
- echo "Using $KEYNAME and endpoint $ENDPOINT" - echo "Using $KEYNAME and endpoint $ENDPOINT"
``` ```
Dotenv files can also be specified at the task level: dotenvファイルはタスクレベルでも使用可能です:
```yaml ```yaml
version: '3' version: '3'
@ -173,7 +173,7 @@ tasks:
- echo "Using $KEYNAME and endpoint $ENDPOINT" - echo "Using $KEYNAME and endpoint $ENDPOINT"
``` ```
Environment variables specified explicitly at the task-level will override variables defined in dotfiles: タスクレベルで明示的に定義された環境変数は、dotenvで読み込んだ変数を上書きします:
```yaml ```yaml
version: '3' version: '3'
@ -192,11 +192,11 @@ tasks:
:::info :::info
Please note that you are not currently able to use the `dotenv` key inside included Taskfiles. インクルードされたTaskfile内では、`dotenv`設定が現在は使えないことに注意してください。
::: :::
## Including other Taskfiles ## 他のTaskfileをインクルードする
If you want to share tasks between different projects (Taskfiles), you can use the importing mechanism to include other Taskfiles using the `includes` keyword: If you want to share tasks between different projects (Taskfiles), you can use the importing mechanism to include other Taskfiles using the `includes` keyword:
@ -789,7 +789,7 @@ tasks:
vars: [IMAGE_NAME, IMAGE_TAG] vars: [IMAGE_NAME, IMAGE_TAG]
``` ```
## Variables ## 変数
When doing interpolation of variables, Task will look for the below. They are listed below in order of importance (i.e. most important first): When doing interpolation of variables, Task will look for the below. They are listed below in order of importance (i.e. most important first):
@ -863,6 +863,168 @@ tasks:
This works for all types of variables. This works for all types of variables.
## Looping over values
Task allows you to loop over certain values and execute a command for each. There are a number of ways to do this depending on the type of value you want to loop over.
### Looping over a static list
The simplest kind of loop is an explicit one. This is useful when you want to loop over a set of values that are known ahead of time.
```yaml
version: '3'
tasks:
default:
cmds:
- for: ['foo.txt', 'bar.txt']
cmd: cat {{ .ITEM }}
```
### Looping over your task's sources
You are also able to loop over the sources of your task:
```yaml
version: '3'
tasks:
default:
sources:
- foo.txt
- bar.txt
cmds:
- for: sources
cmd: cat {{ .ITEM }}
```
This will also work if you use globbing syntax in your sources. For example, if you specify a source for `*.txt`, the loop will iterate over all files that match that glob.
Source paths will always be returned as paths relative to the task directory. If you need to convert this to an absolute path, you can use the built-in `joinPath` function:
```yaml
version: '3'
tasks:
default:
vars:
MY_DIR: /path/to/dir
dir: '{{.MY_DIR}}'
sources:
- foo.txt
- bar.txt
cmds:
- for: sources
cmd: cat {{ joinPath .MY_DIR .ITEM }}
```
### Looping over variables
To loop over the contents of a variable, you simply need to specify the variable you want to loop over. By default, variables will be split on any whitespace characters.
```yaml
version: '3'
tasks:
default:
vars:
my_var: foo.txt bar.txt
cmds:
- for:
var: my_var
cmd: cat {{ .ITEM }}
```
If you need to split on a different character, you can do this by specifying the `split` property:
```yaml
version: '3'
tasks:
default:
vars:
my_var: foo.txt,bar.txt
cmds:
- for:
var: my_var
split: ','
cmd: cat {{ .ITEM }}
```
All of this also works with dynamic variables!
```yaml
version: '3'
tasks:
default:
vars:
my_var:
sh: find -type f -name '*.txt'
cmds:
- for:
var: my_var
cmd: cat {{ .ITEM }}
```
### Renaming variables
If you want to rename the iterator variable to make it clearer what the value contains, you can do so by specifying the `as` property:
```yaml
version: '3'
tasks:
default:
vars:
my_var: foo.txt bar.txt
cmds:
- for:
var: my_var
as: FILE
cmd: cat {{ .FILE }}
```
### Looping over tasks
Because the `for` property is defined at the `cmds` level, you can also use it alongside the `task` keyword to run tasks multiple times with different variables.
```yaml
version: '3'
tasks:
default:
cmds:
- for: [foo, bar]
task: my-task
vars:
FILE: '{{ .ITEM }}'
my-task:
cmds:
- echo '{{ .FILE }}'
```
Or if you want to run different tasks depending on the value of the loop:
```yaml
version: '3'
tasks:
default:
cmds:
- for: [foo, bar]
task: task-{{ .ITEM }}
task-foo:
cmds:
- echo 'foo'
task-bar:
cmds:
- echo 'bar'
```
## Forwarding CLI arguments to commands ## Forwarding CLI arguments to commands
If `--` is given in the CLI, all following parameters are added to a special `.CLI_ARGS` variable. This is useful to forward arguments to another command. If `--` is given in the CLI, all following parameters are added to a special `.CLI_ARGS` variable. This is useful to forward arguments to another command.
@ -1008,9 +1170,9 @@ would print the following output:
If you want to see all tasks, there's a `--list-all` (alias `-a`) flag as well. If you want to see all tasks, there's a `--list-all` (alias `-a`) flag as well.
## Display summary of task ## タスクの概要を表示する
Running `task --summary task-name` will show a summary of a task. The following Taskfile: `task --summary task-name`を実行することでタスクの概要が表示されます。 Taskfileの例:
```yaml ```yaml
version: '3' version: '3'
@ -1031,7 +1193,7 @@ tasks:
- your-build-tool - your-build-tool
``` ```
with running `task --summary release` would print the following output: `task --summary release`を実行することで、以下のように出力されます:
``` ```
task: release task: release
@ -1048,11 +1210,11 @@ commands:
- your-release-tool - your-release-tool
``` ```
If a summary is missing, the description will be printed. If the task does not have a summary or a description, a warning is printed. summaryがない場合はdescriptionが表示されます。 summaryもdescriptionもない場合は警告が表示されます。
Please note: _showing the summary will not execute the command_. 注意: _概要を表示するときはコマンドは実行されません_
## Task aliases ## タスクのエイリアス
Aliases are alternative names for tasks. They can be used to make it easier and quicker to run tasks with long or hard-to-type names. You can use them on the command line, when [calling sub-tasks](#calling-another-task) in your Taskfile and when [including tasks](#including-other-taskfiles) with aliases from another Taskfile. They can also be used together with [namespace aliases](#namespace-aliases). Aliases are alternative names for tasks. They can be used to make it easier and quicker to run tasks with long or hard-to-type names. You can use them on the command line, when [calling sub-tasks](#calling-another-task) in your Taskfile and when [including tasks](#including-other-taskfiles) with aliases from another Taskfile. They can also be used together with [namespace aliases](#namespace-aliases).
@ -1071,7 +1233,7 @@ tasks:
- echo "generating..." - echo "generating..."
``` ```
## Overriding task name ## タスク名の上書き
Sometimes you may want to override the task name printed on the summary, up-to-date messages to STDOUT, etc. In this case, you can just set `label:`, which can also be interpolated with variables: Sometimes you may want to override the task name printed on the summary, up-to-date messages to STDOUT, etc. In this case, you can just set `label:`, which can also be interpolated with variables:
@ -1093,7 +1255,7 @@ tasks:
- echo "{{.MESSAGE}}" - echo "{{.MESSAGE}}"
``` ```
## Warning Prompts ## 警告プロンプト
Warning Prompts are used to prompt a user for confirmation before a task is executed. Warning Prompts are used to prompt a user for confirmation before a task is executed.
@ -1147,7 +1309,7 @@ Tasks with prompts always fail by default on non-terminal environments, like a C
::: :::
## Silent mode ## サイレントモード
Silent mode disables the echoing of commands before Task runs it. For the following Taskfile: Silent mode disables the echoing of commands before Task runs it. For the following Taskfile:
@ -1365,7 +1527,7 @@ The `output` option can also be specified by the `--output` or `-o` flags.
::: :::
## Interactive CLI application ## 対話型CLIアプリケーション
When running interactive CLI applications inside Task they can sometimes behave weirdly, especially when the [output mode](#output-syntax) is set to something other than `interleaved` (the default), or when interactive apps are run in parallel with other tasks. When running interactive CLI applications inside Task they can sometimes behave weirdly, especially when the [output mode](#output-syntax) is set to something other than `interleaved` (the default), or when interactive apps are run in parallel with other tasks.
@ -1398,7 +1560,7 @@ tasks:
- ./app{{exeExt}} -h localhost -p 8080 - ./app{{exeExt}} -h localhost -p 8080
``` ```
## `set` and `shopt` ## `set`と`shopt`
It's possible to specify options to the [`set`](https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html) and [`shopt`](https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html) builtins. This can be added at global, task or command level. It's possible to specify options to the [`set`](https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html) and [`shopt`](https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html) builtins. This can be added at global, task or command level.

View File

@ -1,26 +1,26 @@
{ {
"link.title.Pages": { "link.title.Pages": {
"message": "Pages", "message": "ページ",
"description": "The title of the footer links column with title=Pages in the footer" "description": "The title of the footer links column with title=Pages in the footer"
}, },
"link.title.Community": { "link.title.Community": {
"message": "Community", "message": "コミュニティー",
"description": "The title of the footer links column with title=Community in the footer" "description": "The title of the footer links column with title=Community in the footer"
}, },
"link.title.Translations": { "link.title.Translations": {
"message": "Translations", "message": "翻訳",
"description": "The title of the footer links column with title=Translations in the footer" "description": "The title of the footer links column with title=Translations in the footer"
}, },
"link.item.label.Installation": { "link.item.label.Installation": {
"message": "Installation", "message": "インストール方法",
"description": "The label of footer link with label=Installation linking to /installation/" "description": "The label of footer link with label=Installation linking to /installation/"
}, },
"link.item.label.Usage": { "link.item.label.Usage": {
"message": "Usage", "message": "使い方",
"description": "The label of footer link with label=Usage linking to /usage/" "description": "The label of footer link with label=Usage linking to /usage/"
}, },
"link.item.label.Donate": { "link.item.label.Donate": {
"message": "Donate", "message": "寄付",
"description": "The label of footer link with label=Donate linking to /donate/" "description": "The label of footer link with label=Donate linking to /donate/"
}, },
"link.item.label.GitHub": { "link.item.label.GitHub": {

View File

@ -4,11 +4,11 @@
"description": "The title in the navbar" "description": "The title in the navbar"
}, },
"item.label.Installation": { "item.label.Installation": {
"message": "Installation", "message": "インストール方法",
"description": "Navbar item with label Installation" "description": "Navbar item with label Installation"
}, },
"item.label.Usage": { "item.label.Usage": {
"message": "Usage", "message": "使い方",
"description": "Navbar item with label Usage" "description": "Navbar item with label Usage"
}, },
"item.label.API": { "item.label.API": {
@ -16,7 +16,7 @@
"description": "Navbar item with label API" "description": "Navbar item with label API"
}, },
"item.label.Donate": { "item.label.Donate": {
"message": "Donate", "message": "寄付",
"description": "Navbar item with label Donate" "description": "Navbar item with label Donate"
}, },
"item.label.GitHub": { "item.label.GitHub": {

View File

@ -55,9 +55,9 @@ Se `--` é informado, todos os argumentos remanescentes serão atribuídos a uma
O Task às vezes fecha com códigos de saída específicos. Estes códigos são divididos em três grupos com os seguintes intervalos: O Task às vezes fecha com códigos de saída específicos. Estes códigos são divididos em três grupos com os seguintes intervalos:
- Erros gerais (0-99) - General errors (0-99)
- Erros de Taskfile (100-199) - Taskfile errors (100-199)
- Erros de execução de tarefa (200-299) - Task errors (200-299)
Uma lista completa dos códigos de saída e suas descrições podem ser encontradas abaixo: Uma lista completa dos códigos de saída e suas descrições podem ser encontradas abaixo:
@ -113,19 +113,20 @@ Quando estiver usando o modificador `--json` em combinação com o modificador `
Há algumas variáveis especiais que são acessíveis via template: Há algumas variáveis especiais que são acessíveis via template:
| Variável | Descrição | | Variável | Descrição |
| ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `CLI_ARGS` | Contém todos os argumentos extras passados depois de `--` quando invocando o Task via linha de comando. | | `CLI_ARGS` | Contém todos os argumentos extras passados depois de `--` quando invocando o Task via linha de comando. |
| `TASK` | O nome da tarefa atual. | | `TASK` | O nome da tarefa atual. |
| `ROOT_DIR` | O caminho absoluto para o Taskfile raíz. | | `ROOT_DIR` | O caminho absoluto para o Taskfile raíz. |
| `TASKFILE_DIR` | O caminho absoluto para o Taskfile incluído. | | `TASKFILE_DIR` | O caminho absoluto para o Taskfile incluído. |
| `USER_WORKING_DIR` | O caminho absoluto a partir do qual o comando `task` foi invocado. | | `USER_WORKING_DIR` | O caminho absoluto a partir do qual o comando `task` foi invocado. |
| `CHECKSUM` | O "checksum" dos arquivos listados em `sources`. Apenas disponível dentro do atributo `status` e se o método estiver configurado como `checksum`. | | `CHECKSUM` | O "checksum" dos arquivos listados em `sources`. Apenas disponível dentro do atributo `status` e se o método estiver configurado como `checksum`. |
| `TIMESTAMP` | A maior data de modificação entre os arquivos listados em `sources`. Apenas disponível dentro do atributo `status` e se o método estiver configurado como `timestamp`. | | `TIMESTAMP` | The date object of the greatest timestamp of the files listed in `sources`. Apenas disponível dentro do atributo `status` e se o método estiver configurado como `timestamp`. |
| `TASK_VERSION` | A versão atual do Task. | | `TASK_VERSION` | A versão atual do Task. |
| `ITEM` | The value of the current iteration when using the `for` property. |
## ENV ## ENV
Algumas variáveis de ambiente podem ser configuradas para mudar o comportamento do Task. Some environment variables can be overridden to adjust Task behavior.
| ENV | Padrão | Descrição | | ENV | Padrão | Descrição |
| -------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------- | | -------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
@ -254,8 +255,9 @@ tasks:
| Atributo | Tipo | Padrão | Descrição | | Atributo | Tipo | Padrão | Descrição |
| -------------- | ---------------------------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | -------------- | ---------------------------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `cmd` | `string` | | The shell command to be executed. | | `cmd` | `string` | | The shell command to be executed. |
| `silent` | `bool` | `false` | Skips some output for this command. Note that STDOUT and STDERR of the commands will still be redirected. |
| `task` | `string` | | Set this to trigger execution of another task instead of running a command. This cannot be set together with `cmd`. | | `task` | `string` | | Set this to trigger execution of another task instead of running a command. This cannot be set together with `cmd`. |
| `for` | [`For`](#for) | | Runs the command once for each given value. |
| `silent` | `bool` | `false` | Skips some output for this command. Note that STDOUT and STDERR of the commands will still be redirected. |
| `vars` | [`map[string]Variable`](#variable) | | Optional additional variables to be passed to the referenced task. Only relevant when setting `task` instead of `cmd`. | | `vars` | [`map[string]Variable`](#variable) | | Optional additional variables to be passed to the referenced task. Only relevant when setting `task` instead of `cmd`. |
| `ignore_error` | `bool` | `false` | Continue execution if errors happen while executing the command. | | `ignore_error` | `bool` | `false` | Continue execution if errors happen while executing the command. |
| `defer` | `string` | | Alternative to `cmd`, but schedules the command to be executed at the end of this task instead of immediately. This cannot be used together with `cmd`. | | `defer` | `string` | | Alternative to `cmd`, but schedules the command to be executed at the end of this task instead of immediately. This cannot be used together with `cmd`. |
@ -297,10 +299,26 @@ tasks:
::: :::
#### Precondition #### For
The `for` parameter can be defined as a string, a list of strings or a map. If it is defined as a string, you can give it any of the following values:
- `source` - Will run the command for each source file defined on the task. (Glob patterns will be resolved, so `*.go` will run for every Go file that matches).
If it is defined as a list of strings, the command will be run for each value.
Finally, the `for` parameter can be defined as a map when you want to use a variable to define the values to loop over:
| Atributo | Tipo | Padrão | Descrição | | Atributo | Tipo | Padrão | Descrição |
| -------- | -------- | ------ | ------------------------------------------------------------------------------------------------------------ | | -------- | -------- | ---------------- | -------------------------------------------- |
| `var` | `string` | | The name of the variable to use as an input. |
| `split` | `string` | (any whitespace) | What string the variable should be split on. |
| `as` | `string` | `ITEM` | The name of the iterator variable. |
#### Precondition
| Attribute | Type | Default | Description |
| --------- | -------- | ------- | ------------------------------------------------------------------------------------------------------------ |
| `sh` | `string` | | Command to be executed. If a non-zero exit code is returned, the task errors without executing its commands. | | `sh` | `string` | | Command to be executed. If a non-zero exit code is returned, the task errors without executing its commands. |
| `msg` | `string` | | Optional message to print if the precondition isn't met. | | `msg` | `string` | | Optional message to print if the precondition isn't met. |

View File

@ -863,6 +863,168 @@ tasks:
This works for all types of variables. This works for all types of variables.
## Looping over values
Task allows you to loop over certain values and execute a command for each. There are a number of ways to do this depending on the type of value you want to loop over.
### Looping over a static list
The simplest kind of loop is an explicit one. This is useful when you want to loop over a set of values that are known ahead of time.
```yaml
version: '3'
tasks:
default:
cmds:
- for: ['foo.txt', 'bar.txt']
cmd: cat {{ .ITEM }}
```
### Looping over your task's sources
You are also able to loop over the sources of your task:
```yaml
version: '3'
tasks:
default:
sources:
- foo.txt
- bar.txt
cmds:
- for: sources
cmd: cat {{ .ITEM }}
```
This will also work if you use globbing syntax in your sources. For example, if you specify a source for `*.txt`, the loop will iterate over all files that match that glob.
Source paths will always be returned as paths relative to the task directory. If you need to convert this to an absolute path, you can use the built-in `joinPath` function:
```yaml
version: '3'
tasks:
default:
vars:
MY_DIR: /path/to/dir
dir: '{{.MY_DIR}}'
sources:
- foo.txt
- bar.txt
cmds:
- for: sources
cmd: cat {{ joinPath .MY_DIR .ITEM }}
```
### Looping over variables
To loop over the contents of a variable, you simply need to specify the variable you want to loop over. By default, variables will be split on any whitespace characters.
```yaml
version: '3'
tasks:
default:
vars:
my_var: foo.txt bar.txt
cmds:
- for:
var: my_var
cmd: cat {{ .ITEM }}
```
If you need to split on a different character, you can do this by specifying the `split` property:
```yaml
version: '3'
tasks:
default:
vars:
my_var: foo.txt,bar.txt
cmds:
- for:
var: my_var
split: ','
cmd: cat {{ .ITEM }}
```
All of this also works with dynamic variables!
```yaml
version: '3'
tasks:
default:
vars:
my_var:
sh: find -type f -name '*.txt'
cmds:
- for:
var: my_var
cmd: cat {{ .ITEM }}
```
### Renaming variables
If you want to rename the iterator variable to make it clearer what the value contains, you can do so by specifying the `as` property:
```yaml
version: '3'
tasks:
default:
vars:
my_var: foo.txt bar.txt
cmds:
- for:
var: my_var
as: FILE
cmd: cat {{ .FILE }}
```
### Looping over tasks
Because the `for` property is defined at the `cmds` level, you can also use it alongside the `task` keyword to run tasks multiple times with different variables.
```yaml
version: '3'
tasks:
default:
cmds:
- for: [foo, bar]
task: my-task
vars:
FILE: '{{ .ITEM }}'
my-task:
cmds:
- echo '{{ .FILE }}'
```
Or if you want to run different tasks depending on the value of the loop:
```yaml
version: '3'
tasks:
default:
cmds:
- for: [foo, bar]
task: task-{{ .ITEM }}
task-foo:
cmds:
- echo 'foo'
task-bar:
cmds:
- echo 'bar'
```
## Forwarding CLI arguments to commands ## Forwarding CLI arguments to commands
If `--` is given in the CLI, all following parameters are added to a special `.CLI_ARGS` variable. This is useful to forward arguments to another command. If `--` is given in the CLI, all following parameters are added to a special `.CLI_ARGS` variable. This is useful to forward arguments to another command.

View File

@ -120,12 +120,13 @@ There are some special variables that is available on the templating system:
| `TASKFILE_DIR` | The absolute path of the included Taskfile. | | `TASKFILE_DIR` | The absolute path of the included Taskfile. |
| `USER_WORKING_DIR` | The absolute path of the directory `task` was called from. | | `USER_WORKING_DIR` | The absolute path of the directory `task` was called from. |
| `CHECKSUM` | The checksum of the files listed in `sources`. Only available within the `status` prop and if method is set to `checksum`. | | `CHECKSUM` | The checksum of the files listed in `sources`. Only available within the `status` prop and if method is set to `checksum`. |
| `TIMESTAMP` | The date object of the greatest timestamp of the files listes in `sources`. Only available within the `status` prop and if method is set to `timestamp`. | | `TIMESTAMP` | The date object of the greatest timestamp of the files listed in `sources`. Only available within the `status` prop and if method is set to `timestamp`. |
| `TASK_VERSION` | The current version of task. | | `TASK_VERSION` | The current version of task. |
| `ITEM` | The value of the current iteration when using the `for` property. |
## ENV ## ENV
Some environment variables can be overriden to adjust Task behavior. Some environment variables can be overridden to adjust Task behavior.
| ENV | Default | Description | | ENV | Default | Description |
| -------------------- | ------- | ----------------------------------------------------------------------------------------------------------------- | | -------------------- | ------- | ----------------------------------------------------------------------------------------------------------------- |
@ -254,8 +255,9 @@ tasks:
| Атрибут | Тип | По умолчанию | Описание | | Атрибут | Тип | По умолчанию | Описание |
| -------------- | ---------------------------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | -------------- | ---------------------------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `cmd` | `string` | | The shell command to be executed. | | `cmd` | `string` | | The shell command to be executed. |
| `silent` | `bool` | `false` | Skips some output for this command. Note that STDOUT and STDERR of the commands will still be redirected. |
| `task` | `string` | | Set this to trigger execution of another task instead of running a command. This cannot be set together with `cmd`. | | `task` | `string` | | Set this to trigger execution of another task instead of running a command. This cannot be set together with `cmd`. |
| `for` | [`For`](#for) | | Runs the command once for each given value. |
| `silent` | `bool` | `false` | Skips some output for this command. Note that STDOUT and STDERR of the commands will still be redirected. |
| `vars` | [`map[string]Variable`](#variable) | | Optional additional variables to be passed to the referenced task. Only relevant when setting `task` instead of `cmd`. | | `vars` | [`map[string]Variable`](#variable) | | Optional additional variables to be passed to the referenced task. Only relevant when setting `task` instead of `cmd`. |
| `ignore_error` | `bool` | `false` | Continue execution if errors happen while executing the command. | | `ignore_error` | `bool` | `false` | Continue execution if errors happen while executing the command. |
| `defer` | `string` | | Alternative to `cmd`, but schedules the command to be executed at the end of this task instead of immediately. This cannot be used together with `cmd`. | | `defer` | `string` | | Alternative to `cmd`, but schedules the command to be executed at the end of this task instead of immediately. This cannot be used together with `cmd`. |
@ -297,10 +299,26 @@ tasks:
::: :::
#### Precondition #### For
The `for` parameter can be defined as a string, a list of strings or a map. If it is defined as a string, you can give it any of the following values:
- `source` - Will run the command for each source file defined on the task. (Glob patterns will be resolved, so `*.go` will run for every Go file that matches).
If it is defined as a list of strings, the command will be run for each value.
Finally, the `for` parameter can be defined as a map when you want to use a variable to define the values to loop over:
| Атрибут | Тип | По умолчанию | Description | | Атрибут | Тип | По умолчанию | Description |
| ------- | -------- | ------------ | ------------------------------------------------------------------------------------------------------------ | | ------- | -------- | ---------------- | -------------------------------------------- |
| `var` | `string` | | The name of the variable to use as an input. |
| `split` | `string` | (any whitespace) | What string the variable should be split on. |
| `as` | `string` | `ITEM` | The name of the iterator variable. |
#### Precondition
| Attribute | Type | Default | Description |
| --------- | -------- | ------- | ------------------------------------------------------------------------------------------------------------ |
| `sh` | `string` | | Command to be executed. If a non-zero exit code is returned, the task errors without executing its commands. | | `sh` | `string` | | Command to be executed. If a non-zero exit code is returned, the task errors without executing its commands. |
| `msg` | `string` | | Optional message to print if the precondition isn't met. | | `msg` | `string` | | Optional message to print if the precondition isn't met. |

View File

@ -863,6 +863,168 @@ tasks:
This works for all types of variables. This works for all types of variables.
## Looping over values
Task allows you to loop over certain values and execute a command for each. There are a number of ways to do this depending on the type of value you want to loop over.
### Looping over a static list
The simplest kind of loop is an explicit one. This is useful when you want to loop over a set of values that are known ahead of time.
```yaml
version: '3'
tasks:
default:
cmds:
- for: ['foo.txt', 'bar.txt']
cmd: cat {{ .ITEM }}
```
### Looping over your task's sources
You are also able to loop over the sources of your task:
```yaml
version: '3'
tasks:
default:
sources:
- foo.txt
- bar.txt
cmds:
- for: sources
cmd: cat {{ .ITEM }}
```
This will also work if you use globbing syntax in your sources. For example, if you specify a source for `*.txt`, the loop will iterate over all files that match that glob.
Source paths will always be returned as paths relative to the task directory. If you need to convert this to an absolute path, you can use the built-in `joinPath` function:
```yaml
version: '3'
tasks:
default:
vars:
MY_DIR: /path/to/dir
dir: '{{.MY_DIR}}'
sources:
- foo.txt
- bar.txt
cmds:
- for: sources
cmd: cat {{ joinPath .MY_DIR .ITEM }}
```
### Looping over variables
To loop over the contents of a variable, you simply need to specify the variable you want to loop over. By default, variables will be split on any whitespace characters.
```yaml
version: '3'
tasks:
default:
vars:
my_var: foo.txt bar.txt
cmds:
- for:
var: my_var
cmd: cat {{ .ITEM }}
```
If you need to split on a different character, you can do this by specifying the `split` property:
```yaml
version: '3'
tasks:
default:
vars:
my_var: foo.txt,bar.txt
cmds:
- for:
var: my_var
split: ','
cmd: cat {{ .ITEM }}
```
All of this also works with dynamic variables!
```yaml
version: '3'
tasks:
default:
vars:
my_var:
sh: find -type f -name '*.txt'
cmds:
- for:
var: my_var
cmd: cat {{ .ITEM }}
```
### Renaming variables
If you want to rename the iterator variable to make it clearer what the value contains, you can do so by specifying the `as` property:
```yaml
version: '3'
tasks:
default:
vars:
my_var: foo.txt bar.txt
cmds:
- for:
var: my_var
as: FILE
cmd: cat {{ .FILE }}
```
### Looping over tasks
Because the `for` property is defined at the `cmds` level, you can also use it alongside the `task` keyword to run tasks multiple times with different variables.
```yaml
version: '3'
tasks:
default:
cmds:
- for: [foo, bar]
task: my-task
vars:
FILE: '{{ .ITEM }}'
my-task:
cmds:
- echo '{{ .FILE }}'
```
Or if you want to run different tasks depending on the value of the loop:
```yaml
version: '3'
tasks:
default:
cmds:
- for: [foo, bar]
task: task-{{ .ITEM }}
task-foo:
cmds:
- echo 'foo'
task-bar:
cmds:
- echo 'bar'
```
## Forwarding CLI arguments to commands ## Forwarding CLI arguments to commands
If `--` is given in the CLI, all following parameters are added to a special `.CLI_ARGS` variable. This is useful to forward arguments to another command. If `--` is given in the CLI, all following parameters are added to a special `.CLI_ARGS` variable. This is useful to forward arguments to another command.

View File

@ -120,12 +120,13 @@ There are some special variables that is available on the templating system:
| `TASKFILE_DIR` | The absolute path of the included Taskfile. | | `TASKFILE_DIR` | The absolute path of the included Taskfile. |
| `USER_WORKING_DIR` | The absolute path of the directory `task` was called from. | | `USER_WORKING_DIR` | The absolute path of the directory `task` was called from. |
| `CHECKSUM` | The checksum of the files listed in `sources`. Only available within the `status` prop and if method is set to `checksum`. | | `CHECKSUM` | The checksum of the files listed in `sources`. Only available within the `status` prop and if method is set to `checksum`. |
| `TIMESTAMP` | The date object of the greatest timestamp of the files listes in `sources`. Only available within the `status` prop and if method is set to `timestamp`. | | `TIMESTAMP` | The date object of the greatest timestamp of the files listed in `sources`. Only available within the `status` prop and if method is set to `timestamp`. |
| `TASK_VERSION` | The current version of task. | | `TASK_VERSION` | The current version of task. |
| `ITEM` | The value of the current iteration when using the `for` property. |
## ENV ## ENV
Some environment variables can be overriden to adjust Task behavior. Some environment variables can be overridden to adjust Task behavior.
| ENV | Default | Description | | ENV | Default | Description |
| -------------------- | ------- | ----------------------------------------------------------------------------------------------------------------- | | -------------------- | ------- | ----------------------------------------------------------------------------------------------------------------- |
@ -254,8 +255,9 @@ tasks:
| Attribute | Type | Default | Description | | Attribute | Type | Default | Description |
| -------------- | ---------------------------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | -------------- | ---------------------------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `cmd` | `string` | | The shell command to be executed. | | `cmd` | `string` | | The shell command to be executed. |
| `silent` | `bool` | `false` | Skips some output for this command. Note that STDOUT and STDERR of the commands will still be redirected. |
| `task` | `string` | | Set this to trigger execution of another task instead of running a command. This cannot be set together with `cmd`. | | `task` | `string` | | Set this to trigger execution of another task instead of running a command. This cannot be set together with `cmd`. |
| `for` | [`For`](#for) | | Runs the command once for each given value. |
| `silent` | `bool` | `false` | Skips some output for this command. Note that STDOUT and STDERR of the commands will still be redirected. |
| `vars` | [`map[string]Variable`](#variable) | | Optional additional variables to be passed to the referenced task. Only relevant when setting `task` instead of `cmd`. | | `vars` | [`map[string]Variable`](#variable) | | Optional additional variables to be passed to the referenced task. Only relevant when setting `task` instead of `cmd`. |
| `ignore_error` | `bool` | `false` | Continue execution if errors happen while executing the command. | | `ignore_error` | `bool` | `false` | Continue execution if errors happen while executing the command. |
| `defer` | `string` | | Alternative to `cmd`, but schedules the command to be executed at the end of this task instead of immediately. This cannot be used together with `cmd`. | | `defer` | `string` | | Alternative to `cmd`, but schedules the command to be executed at the end of this task instead of immediately. This cannot be used together with `cmd`. |
@ -297,6 +299,22 @@ tasks:
::: :::
#### For
The `for` parameter can be defined as a string, a list of strings or a map. If it is defined as a string, you can give it any of the following values:
- `source` - Will run the command for each source file defined on the task. (Glob patterns will be resolved, so `*.go` will run for every Go file that matches).
If it is defined as a list of strings, the command will be run for each value.
Finally, the `for` parameter can be defined as a map when you want to use a variable to define the values to loop over:
| Attribute | Type | Default | Description |
| --------- | -------- | ---------------- | -------------------------------------------- |
| `var` | `string` | | The name of the variable to use as an input. |
| `split` | `string` | (any whitespace) | What string the variable should be split on. |
| `as` | `string` | `ITEM` | The name of the iterator variable. |
#### Precondition #### Precondition
| Attribute | Type | Default | Description | | Attribute | Type | Default | Description |

View File

@ -863,6 +863,168 @@ tasks:
This works for all types of variables. This works for all types of variables.
## Looping over values
Task allows you to loop over certain values and execute a command for each. There are a number of ways to do this depending on the type of value you want to loop over.
### Looping over a static list
The simplest kind of loop is an explicit one. This is useful when you want to loop over a set of values that are known ahead of time.
```yaml
version: '3'
tasks:
default:
cmds:
- for: ['foo.txt', 'bar.txt']
cmd: cat {{ .ITEM }}
```
### Looping over your task's sources
You are also able to loop over the sources of your task:
```yaml
version: '3'
tasks:
default:
sources:
- foo.txt
- bar.txt
cmds:
- for: sources
cmd: cat {{ .ITEM }}
```
This will also work if you use globbing syntax in your sources. For example, if you specify a source for `*.txt`, the loop will iterate over all files that match that glob.
Source paths will always be returned as paths relative to the task directory. If you need to convert this to an absolute path, you can use the built-in `joinPath` function:
```yaml
version: '3'
tasks:
default:
vars:
MY_DIR: /path/to/dir
dir: '{{.MY_DIR}}'
sources:
- foo.txt
- bar.txt
cmds:
- for: sources
cmd: cat {{ joinPath .MY_DIR .ITEM }}
```
### Looping over variables
To loop over the contents of a variable, you simply need to specify the variable you want to loop over. By default, variables will be split on any whitespace characters.
```yaml
version: '3'
tasks:
default:
vars:
my_var: foo.txt bar.txt
cmds:
- for:
var: my_var
cmd: cat {{ .ITEM }}
```
If you need to split on a different character, you can do this by specifying the `split` property:
```yaml
version: '3'
tasks:
default:
vars:
my_var: foo.txt,bar.txt
cmds:
- for:
var: my_var
split: ','
cmd: cat {{ .ITEM }}
```
All of this also works with dynamic variables!
```yaml
version: '3'
tasks:
default:
vars:
my_var:
sh: find -type f -name '*.txt'
cmds:
- for:
var: my_var
cmd: cat {{ .ITEM }}
```
### Renaming variables
If you want to rename the iterator variable to make it clearer what the value contains, you can do so by specifying the `as` property:
```yaml
version: '3'
tasks:
default:
vars:
my_var: foo.txt bar.txt
cmds:
- for:
var: my_var
as: FILE
cmd: cat {{ .FILE }}
```
### Looping over tasks
Because the `for` property is defined at the `cmds` level, you can also use it alongside the `task` keyword to run tasks multiple times with different variables.
```yaml
version: '3'
tasks:
default:
cmds:
- for: [foo, bar]
task: my-task
vars:
FILE: '{{ .ITEM }}'
my-task:
cmds:
- echo '{{ .FILE }}'
```
Or if you want to run different tasks depending on the value of the loop:
```yaml
version: '3'
tasks:
default:
cmds:
- for: [foo, bar]
task: task-{{ .ITEM }}
task-foo:
cmds:
- echo 'foo'
task-bar:
cmds:
- echo 'bar'
```
## Forwarding CLI arguments to commands ## Forwarding CLI arguments to commands
If `--` is given in the CLI, all following parameters are added to a special `.CLI_ARGS` variable. This is useful to forward arguments to another command. If `--` is given in the CLI, all following parameters are added to a special `.CLI_ARGS` variable. This is useful to forward arguments to another command.

View File

@ -55,9 +55,9 @@ task [--flags] [tasks...] [-- CLI_ARGS...]
Task 有时会以特定的退出代码退出。 These codes are split into three groups with the following ranges: Task 有时会以特定的退出代码退出。 These codes are split into three groups with the following ranges:
- 一般错误 (0-99) - General errors (0-99)
- Taskfile 错误 (100-199) - Taskfile errors (100-199)
- Task 错误 (200-299) - Task errors (200-299)
可以在下面找到退出代码及其描述的完整列表: 可以在下面找到退出代码及其描述的完整列表:
@ -113,19 +113,20 @@ Task 有时会以特定的退出代码退出。 These codes are split into three
模板系统上有一些可用的特殊变量: 模板系统上有一些可用的特殊变量:
| 变量 | 描述 | | 变量 | 描述 |
| ------------------ | ----------------------------------------------------------------------------- | | ------------------ | -------------------------------------------------------------------------------------------------------------------------- |
| `CLI_ARGS` | 当通过 CLI 调用 Task 时,传递包含在 `--` 之后的所有额外参数。 | | `CLI_ARGS` | 当通过 CLI 调用 Task 时,传递包含在 `--` 之后的所有额外参数。 |
| `TASK` | 当前 task 的名称。 | | `TASK` | 当前 task 的名称。 |
| `ROOT_DIR` | 根 Taskfile 的绝对路径。 | | `ROOT_DIR` | 根 Taskfile 的绝对路径。 |
| `TASKFILE_DIR` | 包含 Taskfile 的绝对路径 | | `TASKFILE_DIR` | 包含 Taskfile 的绝对路径 |
| `USER_WORKING_DIR` | 调用 `task` 的目录的绝对路径。 | | `USER_WORKING_DIR` | 调用 `task` 的目录的绝对路径。 |
| `CHECKSUM` | 在 `sources` 中列出的文件的 checksum。 仅在 `status` 参数中可用,并且如果 method 设置为 `checksum`。 | | `CHECKSUM` | 在 `sources` 中列出的文件的 checksum。 仅在 `status` 参数中可用,并且如果 method 设置为 `checksum`。 |
| `TIMESTAMP` | `sources` 中列出的文件的最大时间戳的日期对象。 仅在 `status` 参数中可用,并且如果 method 设置为 `timestamp`。 | | `TIMESTAMP` | The date object of the greatest timestamp of the files listed in `sources`. 仅在 `status` 参数中可用,并且如果 method 设置为 `timestamp`。 |
| `TASK_VERSION` | Task 的当前版本。 | | `TASK_VERSION` | Task 的当前版本。 |
| `ITEM` | The value of the current iteration when using the `for` property. |
## 环境变量 ## 环境变量
可以覆盖某些环境变量以调整 Task 行为。 Some environment variables can be overridden to adjust Task behavior.
| ENV | 默认 | 描述 | | ENV | 默认 | 描述 |
| -------------------- | ------- | ------------------------------------------------------------ | | -------------------- | ------- | ------------------------------------------------------------ |
@ -254,8 +255,9 @@ tasks:
| 属性 | 类型 | 默认 | 描述 | | 属性 | 类型 | 默认 | 描述 |
| -------------- | ---------------------------------- | ------- | -------------------------------------------------------------------------------------------------------------------- | | -------------- | ---------------------------------- | ------- | -------------------------------------------------------------------------------------------------------------------- |
| `cmd` | `string` | | 要执行的 shell 命令 | | `cmd` | `string` | | 要执行的 shell 命令 |
| `silent` | `bool` | `false` | 跳过此命令的一些输出。 请注意,命令的 STDOUT 和 STDERR 仍将被重定向。 |
| `task` | `string` | | 执行另一个 task,而不执行命令。 不能与 `cmd` 同时设置。 | | `task` | `string` | | 执行另一个 task,而不执行命令。 不能与 `cmd` 同时设置。 |
| `for` | [`For`](#for) | | Runs the command once for each given value. |
| `silent` | `bool` | `false` | 跳过此命令的一些输出。 请注意,命令的 STDOUT 和 STDERR 仍将被重定向。 |
| `vars` | [`map[string]Variable`](#variable) | | 要传递给引用 task 的可选附加变量。 仅在设置 `task` 而不是 `cmd` 时相关。 | | `vars` | [`map[string]Variable`](#variable) | | 要传递给引用 task 的可选附加变量。 仅在设置 `task` 而不是 `cmd` 时相关。 |
| `ignore_error` | `bool` | `false` | 执行命令的时候忽略错误,继续执行 | | `ignore_error` | `bool` | `false` | 执行命令的时候忽略错误,继续执行 |
| `defer` | `string` | | `cmd` 的替代方法,但安排命令在此 task 结束时执行,而不是立即执行。 不能与 `cmd` 一同使用。 | | `defer` | `string` | | `cmd` 的替代方法,但安排命令在此 task 结束时执行,而不是立即执行。 不能与 `cmd` 一同使用。 |
@ -297,10 +299,26 @@ tasks:
::: :::
#### Precondition #### For
The `for` parameter can be defined as a string, a list of strings or a map. If it is defined as a string, you can give it any of the following values:
- `source` - Will run the command for each source file defined on the task. (Glob patterns will be resolved, so `*.go` will run for every Go file that matches).
If it is defined as a list of strings, the command will be run for each value.
Finally, the `for` parameter can be defined as a map when you want to use a variable to define the values to loop over:
| 属性 | 类型 | 默认 | 描述 | | 属性 | 类型 | 默认 | 描述 |
| ----- | -------- | -- | --------------------------------------- | | ------- | -------- | ---------------- | -------------------------------------------- |
| `var` | `string` | | The name of the variable to use as an input. |
| `split` | `string` | (any whitespace) | What string the variable should be split on. |
| `as` | `string` | `ITEM` | The name of the iterator variable. |
#### Precondition
| Attribute | Type | Default | Description |
| --------- | -------- | ------- | --------------------------------------- |
| `sh` | `string` | | 要执行的命令。 如果返回非零退出码, task 将在不执行其命令的情况下出错。 | | `sh` | `string` | | 要执行的命令。 如果返回非零退出码, task 将在不执行其命令的情况下出错。 |
| `msg` | `string` | | 如果不满足先决条件,则打印可选消息。 | | `msg` | `string` | | 如果不满足先决条件,则打印可选消息。 |

View File

@ -863,6 +863,168 @@ tasks:
这适用于所有类型的变量。 这适用于所有类型的变量。
## Looping over values
Task allows you to loop over certain values and execute a command for each. There are a number of ways to do this depending on the type of value you want to loop over.
### Looping over a static list
The simplest kind of loop is an explicit one. This is useful when you want to loop over a set of values that are known ahead of time.
```yaml
version: '3'
tasks:
default:
cmds:
- for: ['foo.txt', 'bar.txt']
cmd: cat {{ .ITEM }}
```
### Looping over your task's sources
You are also able to loop over the sources of your task:
```yaml
version: '3'
tasks:
default:
sources:
- foo.txt
- bar.txt
cmds:
- for: sources
cmd: cat {{ .ITEM }}
```
This will also work if you use globbing syntax in your sources. For example, if you specify a source for `*.txt`, the loop will iterate over all files that match that glob.
Source paths will always be returned as paths relative to the task directory. If you need to convert this to an absolute path, you can use the built-in `joinPath` function:
```yaml
version: '3'
tasks:
default:
vars:
MY_DIR: /path/to/dir
dir: '{{.MY_DIR}}'
sources:
- foo.txt
- bar.txt
cmds:
- for: sources
cmd: cat {{ joinPath .MY_DIR .ITEM }}
```
### Looping over variables
To loop over the contents of a variable, you simply need to specify the variable you want to loop over. By default, variables will be split on any whitespace characters.
```yaml
version: '3'
tasks:
default:
vars:
my_var: foo.txt bar.txt
cmds:
- for:
var: my_var
cmd: cat {{ .ITEM }}
```
If you need to split on a different character, you can do this by specifying the `split` property:
```yaml
version: '3'
tasks:
default:
vars:
my_var: foo.txt,bar.txt
cmds:
- for:
var: my_var
split: ','
cmd: cat {{ .ITEM }}
```
All of this also works with dynamic variables!
```yaml
version: '3'
tasks:
default:
vars:
my_var:
sh: find -type f -name '*.txt'
cmds:
- for:
var: my_var
cmd: cat {{ .ITEM }}
```
### Renaming variables
If you want to rename the iterator variable to make it clearer what the value contains, you can do so by specifying the `as` property:
```yaml
version: '3'
tasks:
default:
vars:
my_var: foo.txt bar.txt
cmds:
- for:
var: my_var
as: FILE
cmd: cat {{ .FILE }}
```
### Looping over tasks
Because the `for` property is defined at the `cmds` level, you can also use it alongside the `task` keyword to run tasks multiple times with different variables.
```yaml
version: '3'
tasks:
default:
cmds:
- for: [foo, bar]
task: my-task
vars:
FILE: '{{ .ITEM }}'
my-task:
cmds:
- echo '{{ .FILE }}'
```
Or if you want to run different tasks depending on the value of the loop:
```yaml
version: '3'
tasks:
default:
cmds:
- for: [foo, bar]
task: task-{{ .ITEM }}
task-foo:
cmds:
- echo 'foo'
task-bar:
cmds:
- echo 'bar'
```
## 将 CLI 参数转发到 cmds ## 将 CLI 参数转发到 cmds
如果 `--` 在 CLI 中给出,则所有以下参数都将添加到特殊的 `.CLI_ARGS` 变量中。 这对于将参数转发给另一个命令很有用。 如果 `--` 在 CLI 中给出,则所有以下参数都将添加到特殊的 `.CLI_ARGS` 变量中。 这对于将参数转发给另一个命令很有用。