1
0
mirror of https://github.com/go-task/task.git synced 2025-03-17 21:08:01 +02:00

Website: Sync translations (#1089)

This commit is contained in:
task-bot 2023-03-26 22:43:22 -03:00 committed by GitHub
parent d7d8d3411c
commit 4d4acc72f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 114 additions and 80 deletions

View File

@ -1,6 +1,8 @@
---
slug: /api/
sidebar_position: 4
toc_min_heading_level: 2
toc_max_heading_level: 5
---
# API 参考
@ -15,10 +17,12 @@ task [--flags] [tasks...] [-- CLI_ARGS...]
:::tip
如果 `--` 给出,所有剩余参数将被分配给一个特殊的 `CLI_ARGS` 变量
:::
| 缩写 | 标志 | 类型 | 默认 | 描述 |
| ---- | --------------------------- | -------- | -------------------------------- | --------------------------------------------------------------------------------------------------- |
| `-c` | `--color` | `bool` | `true` | 彩色输出。 默认开启。 设置为 `false` 或使用 `NO_COLOR=1` 禁用。 |
@ -102,9 +106,7 @@ task [--flags] [tasks...] [-- CLI_ARGS...]
| `TASK_COLOR_RED` | `31` | 用于红色的颜色。 |
| `FORCE_COLOR` | | 强制使用颜色输出。 |
## 规则
### Taskfile
## Taskfile Schema
| 属性 | 类型 | 默认 | 描述 |
| ---------- | ---------------------------------- | ------------- | ------------------------------------------------------------------------------------------------- |
@ -135,6 +137,7 @@ task [--flags] [tasks...] [-- CLI_ARGS...]
:::info
像下面这样只赋值一个字符串,和把这个值设置到 `taskfile` 属性是一样的。
```yaml
@ -144,6 +147,29 @@ includes:
:::
### Variable
| 属性 | 类型 | 默认 | 描述 |
| -------- | -------- | -- | ---------------------------------- |
| *itself* | `string` | | 将设置为变量的静态值。 |
| `sh` | `string` | | 一个 shell 命令。 输出 (`STDOUT`) 将分配给变量。 |
:::info
静态和动态变量有不同的语法,如下所示:
```yaml
vars:
STATIC: static
DYNAMIC:
sh: echo "dynamic"
```
:::
### Task
| 属性 | 类型 | 默认 | 描述 |
@ -175,6 +201,7 @@ includes:
:::info
这些替代语法可用。 他们会将给定值设置为 `cmds`,其他所有内容都将设置为其默认值:
```yaml
@ -191,26 +218,8 @@ tasks:
:::
### Dependency
| 属性 | 类型 | 默认 | 描述 |
| ------ | ---------------------------------- | -- | --------------- |
| `task` | `string` | | 要作为依赖项执行的任务。 |
| `vars` | [`map[string]Variable`](#variable) | | 要传递给此任务的可选附加变量。 |
:::tip
如果你不想设置额外的变量,将依赖关系声明为一个字符串列表就足够了(它们将被分配给 `task`)。
```yaml
tasks:
foo:
deps: [foo, bar]
```
:::
### Command
#### Command
| 属性 | 类型 | 默认 | 描述 |
| -------------- | ---------------------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------- |
@ -226,6 +235,7 @@ tasks:
:::info
如果以字符串形式给出,该值将分配给 `cmd`
```yaml
@ -238,27 +248,29 @@ tasks:
:::
### Variable
| 属性 | 类型 | 默认 | 描述 |
| -------- | -------- | -- | ---------------------------------- |
| *itself* | `string` | | 将设置为变量的静态值。 |
| `sh` | `string` | | 一个 shell 命令。 输出 (`STDOUT`) 将分配给变量。 |
#### Dependency
:::info
| 属性 | 类型 | 默认 | 描述 |
| ------ | ---------------------------------- | -- | --------------- |
| `task` | `string` | | 要作为依赖项执行的任务。 |
| `vars` | [`map[string]Variable`](#variable) | | 要传递给此任务的可选附加变量。 |
静态和动态变量有不同的语法,如下所示:
:::tip
如果你不想设置额外的变量,将依赖关系声明为一个字符串列表就足够了(它们将被分配给 `task`)。
```yaml
vars:
STATIC: static
DYNAMIC:
sh: echo "dynamic"
tasks:
foo:
deps: [foo, bar]
```
:::
### Precondition
#### Precondition
| 属性 | 类型 | 默认 | 描述 |
| ----- | -------- | -- | ----------------------------------- |
@ -267,6 +279,7 @@ vars:
:::tip
如果你不想设置不同的消息,你可以像这样声明一个前提条件,值将被分配给 `sh`
```yaml

View File

@ -39,7 +39,7 @@ JetBrains IntelliJ 插件由 [@lechuckroh](https://github.com/lechuckroh) 完成
- [GitHub Actions](https://github.com/arduino/setup-task) 由 [@arduino](https://github.com/arduino) 维护
- [AUR](https://aur.archlinux.org/packages/go-task-bin) 由 [@carlsmedstad](https://github.com/carlsmedstad) 维护
- [Scoop](https://github.com/lukesampson/scoop-extras/blob/master/bucket/task.json)
- [Scoop](https://github.com/ScoopInstaller/Main/blob/master/bucket/task.json)
- [Fedora](https://packages.fedoraproject.org/pkgs/golang-github-task/go-task/)
- [NixOS](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/tools/go-task/default.nix)

View File

@ -11,7 +11,7 @@ Task 提供以下多种安装方式。 查看以下可用方法。
### Homebrew
如果您使用的是 macOS 或 Linux 并安装了 [Homebrew](https://brew.sh/),获取 Task 就像运行一样简单:
如果您使用的是 macOS 或 Linux 并安装了 [Homebrew](https://brew.sh/),获取 Task 就像运行以下命令一样简单:
```bash
brew install go-task/tap/go-task
@ -27,7 +27,7 @@ brew install go-task
### Snap
Task 在 [Snapcraft](https://snapcraft.io/task) 中可用,但请记住,您的 Linux 发行版应该符合 Snaps 的基本约束才能正确安装:
Task 在 [Snapcraft](https://snapcraft.io/task) 中可用,但请记住,您的 Linux 发行版应该符合 Snaps 的基本要求才能正确安装:
```bash
sudo snap install task --classic
@ -35,7 +35,7 @@ sudo snap install task --classic
### Chocolatey
如果 Windows 上安装了 [Chocolatey][choco],再安装 Task 只要这样:
如果 Windows 上安装了 [Chocolatey](https://chocolatey.org/),再安装 Task 只要这样:
```bash
choco install go-task
@ -45,7 +45,7 @@ choco install go-task
### Scoop
如果 Windows 上安装了 [Scoop][scoop],再安装 Task 只要这样:
如果 Windows 上安装了 [Scoop](https://scoop.sh/),再安装 Task 只要这样:
```cmd
scoop install task
@ -105,7 +105,7 @@ npm install -g @go-task/cli
还支持 DEB 和 RPM 包。
`task_checksums.txt` 文件包含每个文件的 SHA-256 校验和
`task_checksums.txt` 文件包含每个文件的 SHA-256 checksum
### 安装脚本
@ -125,10 +125,12 @@ sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b ~/.local/bin
:::caution
在 macOS 和 Windows 上,`~/.local/bin``~/bin` 默认情况下不会添加到 `$PATH`
:::
### GitHub Actions
如果你想在 GitHub Actions 中安装 Task,你可以尝试使用 Arduino 团队的 [这个 action](https://github.com/arduino/setup-task):
@ -160,10 +162,12 @@ env GOBIN=/bin go install github.com/go-task/task/v3/cmd/task@latest
:::tip
对于 CI 环境,我们建议改用 [安装脚本](#get-the-binary),它更快更稳定,因为它只会下载最新发布的二进制文件。
:::
## 自动完成
下载与您的 shell 对应的自动完成文件。
@ -225,6 +229,3 @@ notepad $profile
```shell
Invoke-Expression -Command path/to/task.ps1
```
[choco]: https://chocolatey.org/
[scoop]: https://scoop.sh/

View File

@ -12,9 +12,9 @@ title: 主页
Task 是一个任务运行器/构建工具,旨在比 [GNU Make](https://www.gnu.org/software/make/) 等更简单易用。
由于它是用 [Go](https://go.dev/) 编写的,Task 只是一个二进制文件,没有其他依赖项,这意味着您不需要为了使用构建工具而搞乱任何复杂的安装设置。
由于它是用 [Go](https://go.dev/) 编写的,Task 只是一个二进制文件,没有其他依赖项,这意味着您不需要为了使用构建工具而烦恼任何复杂的安装设置。
[安装](installation.md) 后,您只需在名为 `Taskfile.yml` 的文件中使用简单的 [YAML][yaml] 规则描述您的构建任务:
[安装](installation.md) 后,您只需在名为 `Taskfile.yml` 的文件中使用简单的 [YAML](http://yaml.org/) 规则描述您的构建任务:
```yaml title="Taskfile.yml"
version: '3'
@ -46,4 +46,3 @@ tasks:
| [![Appwrite](/img/appwrite.svg)][appwrite] |
</div>
[yaml]: http://yaml.org/

View File

@ -89,7 +89,7 @@ tasks:
## 版本 2.1
2.1 版包括一个全局 `output` 选项,以允许更好地控制如何将命令输出打印到控制台(有关更多信息,请参阅 [文档][output]):
2.1 版包括一个全局 `output` 选项,以允许更好地控制如何将命令输出打印到控制台(有关更多信息,请参阅 [文档](usage.md#输出语法)):
```yaml
version: '2'
@ -103,7 +103,7 @@ tasks:
prefix: server
```
从这个版本开始,也可以忽略命令或 task 的错误(在 [此处][ignore_errors] 查看文档):
从这个版本开始,也可以忽略命令或 task 的错误(在 [此处](usage.md#忽略错误) 查看文档):
```yaml
version: '2'
@ -149,7 +149,7 @@ tasks:
- aws s3 cp .env s3://myenvironment
```
请检查 [文档][includes]
请检查 [文档](usage.md#包含其他-taskfile)
## 版本 3
@ -202,7 +202,3 @@ tasks:
- 全局或 CLI 变量
- 调用变量
- Task 内的变量
[output]: usage.md#输出语法
[ignore_errors]: usage.md#忽略错误
[includes]: usage.md#包含其他-taskfile

View File

@ -3,13 +3,10 @@ slug: /translate/
sidebar_position: 13
---
# Translate
# 翻译
Want to help us translate this documentation? In this document we explain how.
想帮助我们翻译此文档吗? 在本文档中,我们解释了如何解决这一问题。
Do NOT edit translated markdown files directly on the GitHub repository! We use [Crowdin][crowdin] to allow contributors on work on translations. The repository is periodically updated with progress from Crowdin.
不要直接在 GitHub 存储库上编辑翻译后的 markdown 文件! 我们使用 [Crowdin](https://crowdin.com/project/taskfile) 来允许贡献者进行翻译工作。 存储库会根据 Crowdin 的进展定期更新。
If you want to have access to the Crowdin project to be able to suggest translations, please ask for access on the [#translations channel on our Discord server][discord]. If a given language is not being shown to Crowdin yet, just ask and we can configure it.
[crowdin]: https://crowdin.com/project/taskfile
[discord]: https://discord.gg/6TY36E39UK
如果您想访问 Crowdin 项目以提供翻译建议,请在 [我们的 Discord 服务器上的 #translations 频道](https://discord.gg/6TY36E39UK) 上申请访问权限。 如果给定的语言尚未显示给 Crowdin,请询问,我们可以对其进行配置。

View File

@ -34,7 +34,7 @@ If you omit a task name, "default" will be assumed.
## 支持的文件名称
Task will look for the following file names, in order of priority:
Task 会按以下顺序查找配置文件:
- Taskfile.yml
- Taskfile.yaml
@ -71,6 +71,7 @@ This is useful to have automation that you can run from anywhere in your system!
:::info
When running your global Taskfile with `-g`, tasks will run on `$HOME` by default, and not on your working directory!
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.
@ -91,11 +92,12 @@ tasks:
:::
## 环境变量
### Task
You can use `env` to set custom environment variables for a specific task:
你可以使用 `env` 给每个 task 设置自定义环境变量:
```yaml
version: '3'
@ -124,10 +126,12 @@ tasks:
:::info
`env` supports expansion and retrieving output from a shell command just like variables, as you can see in the [Variables](#variables) section.
:::
### .env 文件
You can also ask Task to include `.env` like files by using the `dotenv:` setting:
@ -154,7 +158,7 @@ tasks:
- echo "Using $KEYNAME and endpoint $ENDPOINT"
```
Dotenv files can also be specified at the task level:
也可以在任务级指定 .env 文件:
```yaml
version: '3'
@ -188,10 +192,12 @@ tasks:
:::info
Please note that you are not currently able to use the `dotenv` key inside included Taskfiles.
请注意,您目前无法在包含的 Taskfile 中使用 `dotenv` 键。
:::
## 包含其他 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:
@ -234,11 +240,13 @@ includes:
:::info
The included Taskfiles must be using the same schema version as the main Taskfile uses.
:::
### Optional includes
### 可选 includes
Includes marked as optional will allow Task to continue execution as normal if the included file is missing.
@ -256,7 +264,7 @@ tasks:
- echo "This command can still be successfully executed if ./tests/Taskfile.yml does not exist"
```
### Internal includes
### 内部 includes
Includes marked as internal will set all the tasks of the included file to be internal as well (see the [Internal tasks](#internal-tasks) section below). This is useful when including utility tasks that are not intended to be used directly by the user.
@ -288,7 +296,7 @@ includes:
DOCKER_IMAGE: frontend_image
```
### 命名空间别名
### 命名空间别名
When including a Taskfile, you can give the namespace a list of `aliases`. This works in the same way as [task aliases](#task-aliases) and can be used together to create shorter and easier-to-type commands.
@ -303,11 +311,13 @@ includes:
:::info
Vars declared in the included Taskfile have preference over the variables in the including Taskfile! If you want a variable in an included Taskfile to be overridable, use the [default function](https://go-task.github.io/slim-sprig/defaults.html): `MY_VAR: '{{.MY_VAR | default "my-default-value"}}'`.
:::
## 内部 task
## 内部 tasks
Internal tasks are tasks that cannot be called directly by the user. They will not appear in the output when running `task --list|--list-all`. Other tasks may call internal tasks in the usual way. This is useful for creating reusable, function-like tasks that have no useful purpose on the command line.
@ -388,10 +398,12 @@ If there is more than one dependency, they always run in parallel for better per
:::tip
You can also make the tasks given by the command line run in parallel by using the `--parallel` flag (alias `-p`). Example: `task --parallel js css`.
:::
If you want to pass information to dependencies, you can do that the same manner as you would to [call another task](#calling-another-task):
```yaml
@ -412,7 +424,7 @@ tasks:
- echo {{.TEXT}}
```
## 平台特定的 task 和 命令
## 平台特定的 tasks 和 cmds
If you want to restrict the running of tasks to explicit platforms, this can be achieved using the `platforms:` key. Tasks can be restricted to a specific OS, architecture or a combination of both. On a mismatch, the task or command will be skipped, and no error will be thrown.
@ -479,7 +491,7 @@ tasks:
- cmd: echo 'Running on all platforms'
```
## 调用另一个任务
## 调用另一个 task
When a task has many dependencies, they are executed concurrently. This will often result in a faster build pipeline. However, in some situations, you may need to call other tasks serially. In this case, use the following syntax:
@ -524,13 +536,15 @@ The above syntax is also supported in `deps`.
:::tip
NOTE: If you want to call a task declared in the root Taskfile from within an [included Taskfile](#including-other-taskfiles), add a leading `:` like this: `task: :task-name`.
:::
## Prevent unnecessary work
### By fingerprinting locally generated files and their sources
## 减少不必要的工作
### 通过指纹识别本地生成的文件及其来源
If a task generates something, you can inform Task the source and generated files, so Task will prevent running them if not necessary.
@ -582,6 +596,7 @@ In situations where you need more flexibility the `status` keyword can be used.
:::info
By default, task stores checksums on a local `.task` directory in the project's directory. Most of the time, you'll want to have this directory on `.gitignore` (or equivalent) so it isn't committed. (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).
If you want these files to be stored in another directory, you can set a `TASK_TEMP_DIR` environment variable in your machine. It can contain a relative path like `tmp/task` that will be interpreted as relative to the project directory, or an absolute or home path like `/tmp/.task` or `~/.task` (subdirectories will be created for each project).
@ -592,27 +607,34 @@ 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.
:::
:::tip
The method `none` skips any validation and always run the task.
:::
:::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.
:::
### Using programmatic checks to indicate a task is up to date.
### 使用程序检查来表示任务是最新的。
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:
@ -666,7 +688,7 @@ tasks:
- grep -q '"dev": false' ./vendor/composer/installed.json
```
### Using programmatic checks to cancel the execution of a task and its dependencies
### 使用程序检查取消任务及其依赖项的执行
In addition to `status` checks, `preconditions` checks are the logical inverse of `status` checks. That is, if you need a certain set of conditions to be _true_ you can use the `preconditions` stanza. `preconditions` are similar to `status` lines, except they support `sh` expansion, and they SHOULD all return 0.
@ -710,7 +732,7 @@ tasks:
- echo "I will not run"
```
### Limiting when tasks run
### 在任务运行时限制
If a task executed by multiple `cmds` or multiple `deps` you can control when it is executed using `run`. `run` can also be set at the root of the Taskfile to change the behavior of all the tasks unless explicitly overridden.
@ -765,10 +787,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
@ -839,7 +863,7 @@ tasks:
- yarn {{.CLI_ARGS}}
```
## Doing task cleanup with `defer`
## 使用 `defer` 做 task 清理
With the `defer` keyword, it's possible to schedule cleanup to be run once the task finishes. The difference with just putting it as the last command is that this command will run even when the task fails.
@ -873,13 +897,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 parse commands as [Go's template engine][gotemplate] before executing them. Variables are accessible through dot syntax (`.VARNAME`).
Task parse commands as [Go's template engine](https://golang.org/pkg/text/template/) before executing them. Variables are accessible through dot syntax (`.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:
@ -1127,7 +1153,7 @@ tasks:
- echo "This will print nothing" > /dev/null
```
## Dry run mode
## 试运行模式
Dry run mode (`--dry`) compiles and steps through each task, printing the commands that would be run without executing them. This is useful for debugging your Taskfiles.
@ -1263,10 +1289,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.
@ -1317,14 +1345,14 @@ 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.
The default watch interval is 5 seconds, but it's possible to change it by either setting `interval: '500ms'` in the root of the Taskfile passing it as an argument like `--interval=500ms`.
[gotemplate]: https://golang.org/pkg/text/template/