mirror of
https://github.com/go-task/task.git
synced 2026-06-28 07:04:33 +00:00
chore(website): sync translations (#1145)
This commit is contained in:
@@ -71,6 +71,7 @@ tasks:
|
||||
|
||||
:::info
|
||||
|
||||
|
||||
当使用 `-g` 运行全局 Taskfile 时,task 将默认在 `$HOME` 上运行,而不是在您的工作目录上!
|
||||
|
||||
如前一节所述,`{{.USER_WORKING_DIR}}` 特殊变量在这里可以非常方便地在您从中调用 `task -g` 的目录中运行内容。
|
||||
@@ -91,6 +92,7 @@ tasks:
|
||||
|
||||
:::
|
||||
|
||||
|
||||
## 环境变量
|
||||
|
||||
### Task
|
||||
@@ -124,10 +126,12 @@ tasks:
|
||||
|
||||
:::info
|
||||
|
||||
|
||||
`env` 支持扩展和检索 shell 命令的输出,就像变量一样,如您在 [变量](#变量) 部分中看到的那样。
|
||||
|
||||
:::
|
||||
|
||||
|
||||
### .env 文件
|
||||
|
||||
您还可以使用 `dotenv:` 设置要求 tasks 包含 `.env` 之类的文件
|
||||
@@ -188,10 +192,12 @@ tasks:
|
||||
|
||||
:::info
|
||||
|
||||
|
||||
请注意,您目前无法在包含的 Taskfile 中使用 `dotenv` 键。
|
||||
|
||||
:::
|
||||
|
||||
|
||||
## 包含其他 Taskfile
|
||||
|
||||
如果要在不同项目(Taskfile)之间共享任务,可以使用导入机制使用 `includes` 关键字包含其他任务文件:
|
||||
@@ -204,7 +210,7 @@ includes:
|
||||
docker: ./DockerTasks.yml
|
||||
```
|
||||
|
||||
给定的 Taskfile 中描述的任务将在指定的命名空间中提供。 因此,您可以从 `documentation/Taskfile.yml` 调用 `task docs:serve` 运行 `serve` task,或者从 `DockerTasks.yml` 文件调用 `task docker:build` 运行 `build` task。
|
||||
给定的 Taskfile 中描述的任务将在指定的命名空间中提供。 因此,您可以调用 `task docs:serve` 从 `documentation/Taskfile.yml` 运行 `serve` task,或者调用 `task docker:build` 从 `DockerTasks.yml` 文件运行 `build` task。
|
||||
|
||||
相对路径是相对于包含包含 Taskfile 的目录解析的。
|
||||
|
||||
@@ -234,10 +240,12 @@ includes:
|
||||
|
||||
:::info
|
||||
|
||||
|
||||
包含的 Taskfile 必须使用与主 Taskfile 使用的相同规则版本。
|
||||
|
||||
:::
|
||||
|
||||
|
||||
### 可选 includes
|
||||
|
||||
如果包含文件丢失,标记为可选的包含将允许 task 继续正常执行。
|
||||
@@ -304,10 +312,12 @@ includes:
|
||||
|
||||
:::info
|
||||
|
||||
|
||||
在包含的 Taskfile 中声明的变量优先于包含 Taskfile 中的变量! 如果您希望包含的 Taskfile 中的变量可被覆盖,请使用 [默认方法](https://go-task.github.io/slim-sprig/defaults.html):`MY_VAR: '{{.MY_VAR | default "my-default-value"}}'`。
|
||||
|
||||
:::
|
||||
|
||||
|
||||
## 内部 tasks
|
||||
|
||||
内部 task 是用户不能直接调用的 task。 运行 `task --list|--list-all` 时,它们不会出现在输出中。 其他 task 可以照常调用内部 task。 这对于创建在命令行上没有用处的可重用、类似函数的 task 很有用。
|
||||
@@ -389,10 +399,12 @@ tasks:
|
||||
|
||||
:::tip
|
||||
|
||||
|
||||
您还可以使用 `--parallel` 标志(别名 `-p`)使命令行给出的 task 并行运行。 例如: `task --parallel js css`。
|
||||
|
||||
:::
|
||||
|
||||
|
||||
如果你想将信息传递给依赖项,你可以像 [调用另一个 task](#调用另一个-task) 一样以相同的方式进行:
|
||||
|
||||
```yaml
|
||||
@@ -525,10 +537,12 @@ tasks:
|
||||
|
||||
:::tip
|
||||
|
||||
|
||||
注意:如果您想从 [包含的 Taskfile](#包含其他-taskfile) 中调用在根 Taskfile 中声明的 task,请像这样添加 `:` 前缀:`task: :task-name`。
|
||||
|
||||
:::
|
||||
|
||||
|
||||
## 减少不必要的工作
|
||||
|
||||
### 通过指纹识别本地生成的文件及其来源
|
||||
@@ -583,7 +597,8 @@ tasks:
|
||||
|
||||
:::info
|
||||
|
||||
默认情况,task 在本地项目的 `.task` 目录保存 checksums 值。 一般都会在 `.gitignore`(或类似配置)中忽略掉这个目录,这样它就不会被提交。 (If you have a task for code generation that is committed it may make sense to commit the checksum of that task as well, though).
|
||||
|
||||
默认情况,task 在本地项目的 `.task` 目录保存 checksums 值。 一般都会在 `.gitignore`(或类似配置)中忽略掉这个目录,这样它就不会被提交。 (如果您有一个已提交的代码生成任务,那么提交该任务的校验和也是有意义的)。
|
||||
|
||||
如果你想要将这些文件存储在另一个目录中,你可以在你的机器中设置一个 `TASK_TEMP_DIR` 环境变量。 可以使用相对路径,比如 `tmp/task`,相对项目根目录,也可以用绝对路径、用户目录路径,比如 `/tmp/.task` 或 `~/.task`(每个项目单独创建子目录)。
|
||||
|
||||
@@ -593,29 +608,36 @@ export TASK_TEMP_DIR='~/.task'
|
||||
|
||||
:::
|
||||
|
||||
|
||||
:::info
|
||||
|
||||
Each task has only one checksum stored for its `sources`. If you want to distinguish a task by any of its input variables, you can add those variables as part of the task's label, and it will be considered a different task.
|
||||
|
||||
This is useful if you want to run a task once for each distinct set of inputs until the sources actually change. For example, if the sources depend on the value of a variable, or you if you want the task to rerun if some arguments change even if the source has not.
|
||||
每个 task 只为其 `sources` 存储一个 checksum。 如果您想通过任何输入变量来区分 task,您可以将这些变量添加为 task 标签的一部分,它将被视为不同的 task。
|
||||
|
||||
如果您想为每个不同的输入集运行一次 task,直到 sources 实际发生变化,这将很有用。 例如,如果 sources 依赖于变量的值,或者您希望在某些参数发生变化时重新运行 task,即使 sources 没有发生变化也是如此。
|
||||
|
||||
:::
|
||||
|
||||
|
||||
:::tip
|
||||
|
||||
|
||||
将 method 设置为 `none` 会跳过任何验证并始终运行任务。
|
||||
|
||||
:::
|
||||
|
||||
|
||||
:::info
|
||||
|
||||
For the `checksum` (default) or `timestamp` method to work, it is only necessary to inform the source files. When the `timestamp` method is used, the last time of the running the task is considered as a generate.
|
||||
|
||||
要使 `checksum`(默认)或 `timestamp` 方法起作用,只需要通知 source 文件即可。 当使用 `timestamp` 方法时,最后一次运行 task 被认为是一次生成。
|
||||
|
||||
:::
|
||||
|
||||
|
||||
### 使用程序检查来表示任务是最新的
|
||||
|
||||
Alternatively, you can inform a sequence of tests as `status`. If no error is returned (exit status 0), the task is considered up-to-date:
|
||||
或者,您可以通知一系列测试作为 `status`。 如果没有错误返回(退出状态 0),task 被认为是最新的:
|
||||
|
||||
```yaml
|
||||
version: '3'
|
||||
@@ -639,7 +661,7 @@ Two special variables `{{.CHECKSUM}}` and `{{.TIMESTAMP}}` are available for int
|
||||
|
||||
Note that the `{{.TIMESTAMP}}` variable is a "live" Go `time.Time` struct, and can be formatted using any of the methods that `time.Time` responds to.
|
||||
|
||||
See [the Go Time documentation](https://golang.org/pkg/time/) for more information.
|
||||
有关详细信息,请参阅 [Go Time 文档](https://golang.org/pkg/time/)。
|
||||
|
||||
如果你想强制任务运行,即使是最新的,你也可以使用 `--force` 或 `-f`。
|
||||
|
||||
@@ -687,7 +709,7 @@ tasks:
|
||||
msg: "One doesn't equal Zero, Halting"
|
||||
```
|
||||
|
||||
Preconditions can set specific failure messages that can tell a user what steps to take using the `msg` field.
|
||||
先决条件可以设置特定的失败消息,这些消息可以使用 `msg` 字段告诉用户要采取什么步骤。
|
||||
|
||||
If a task has a dependency on a sub-task with a precondition, and that precondition is not met - the calling task will fail. Note that a task executed with a failing precondition will not run unless `--force` is given.
|
||||
|
||||
@@ -749,11 +771,11 @@ tasks:
|
||||
|
||||
## 变量
|
||||
|
||||
在进行变量插值时,Task 将查找以下内容。 They are listed below in order of importance (i.e. most important first):
|
||||
在进行变量插值时,Task 将查找以下内容。 它们按权重顺序列在下面(即最重要的第一位):
|
||||
|
||||
- Variables declared in the task definition
|
||||
- Variables given while calling a task from another (See [Calling another task](#calling-another-task) above)
|
||||
- Variables of the [included Taskfile](#including-other-taskfiles) (when the task is included)
|
||||
- task 内部定义的变量
|
||||
- 被其它 task 调用时传入的变量(查看 [调用另一个 task](#调用另一个-task))
|
||||
- [包含其他 Taskfile](#包含其他-taskfile) 中的变量 (当包含其他 task 时)
|
||||
- Variables of the [inclusion of the Taskfile](#vars-of-included-taskfiles) (when the task is included)
|
||||
- Global variables (those declared in the `vars:` option in the Taskfile)
|
||||
- Environment variables
|
||||
@@ -766,10 +788,12 @@ $ TASK_VARIABLE=a-value task do-something
|
||||
|
||||
:::tip
|
||||
|
||||
|
||||
A special variable `.TASK` is always available containing the task name.
|
||||
|
||||
:::
|
||||
|
||||
|
||||
Since some shells do not support the above syntax to set environment variables (Windows) tasks also accept a similar style when not at the beginning of the command.
|
||||
|
||||
```bash
|
||||
@@ -874,13 +898,15 @@ tasks:
|
||||
|
||||
:::info
|
||||
|
||||
|
||||
Due to the nature of how the [Go's own `defer` work](https://go.dev/tour/flowcontrol/13), the deferred commands are executed in the reverse order if you schedule multiple of them.
|
||||
|
||||
:::
|
||||
|
||||
|
||||
## Go 的模板引擎
|
||||
|
||||
Task 在执行命令之前将命令解析为 [Go 的模板引擎][gotemplate]。 可以通过点语法 (`.VARNAME`) 访问变量。
|
||||
Task 在执行命令之前将命令解析为 [Go 的模板引擎](https://golang.org/pkg/text/template/)。 可以通过点语法 (`.VARNAME`) 访问变量。
|
||||
|
||||
All functions by the Go's [slim-sprig lib](https://go-task.github.io/slim-sprig/) are available. The following example gets the current date in a given format:
|
||||
|
||||
@@ -1265,10 +1291,12 @@ $ task default
|
||||
|
||||
:::tip
|
||||
|
||||
|
||||
The `output` option can also be specified by the `--output` or `-o` flags.
|
||||
|
||||
:::
|
||||
|
||||
|
||||
## 交互式 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.
|
||||
@@ -1319,10 +1347,12 @@ tasks:
|
||||
|
||||
:::info
|
||||
|
||||
|
||||
Keep in mind that not all options are available in the [shell interpreter library](https://github.com/mvdan/sh) that Task uses.
|
||||
|
||||
:::
|
||||
|
||||
|
||||
## 观察任务
|
||||
|
||||
With the flags `--watch` or `-w` task will watch for file changes and run the task again. This requires the `sources` attribute to be given, so task knows which files to watch.
|
||||
@@ -1332,4 +1362,3 @@ The default watch interval is 5 seconds, but it's possible to change it by eithe
|
||||
<!-- prettier-ignore-start -->
|
||||
|
||||
<!-- prettier-ignore-end -->
|
||||
[gotemplate]: https://golang.org/pkg/text/template/
|
||||
|
||||
Reference in New Issue
Block a user