作文件

作文件支持用户定义的命令。 这些文件以 YAML 格式编写,并存储在定义命令的目录中。spring-doc.cadn.net.cn

有关用户定义命令的目录结构的更多信息,请参阅有关 Action file Structure 的文档。spring-doc.cadn.net.cn

每个文件都包含一系列作,这些作按照它们在文件中定义的顺序运行。 作执行帮助开发人员向其当前项目添加或修改代码和配置通常需要的任务。 作可以运行另一个可执行应用程序,这有助于自动执行开发任务,例如使用供应商的 CLI 应用程序进行部署。spring-doc.cadn.net.cn

一个目录中可以有多个作文件,并且它们按字母顺序进行评估。spring-doc.cadn.net.cn

评估顺序在将来的版本中可能会更改。

目前,只有少数作存在,但更多作已成为原型,即将推出。spring-doc.cadn.net.cn

作列表包括:spring-doc.cadn.net.cn

一个介绍性示例

The CLIcommand newcommand 创建一个简单的用户定义的命令,我们可以使用它来演示 actions 文件的组件。spring-doc.cadn.net.cn

spring command new --commandName hello --subCommandName create
Created user defined command /home/testing/rest-service/.spring/commands/hello/create

目录结构为spring-doc.cadn.net.cn

$ tree .spring
.spring
└── commands
    └── hello
        └── create
            ├── command.yaml
            └── hello.yaml

的内容command.yaml,如下所示,它定义了一个名为greeting. 此参数用于hello.yaml作文件。spring-doc.cadn.net.cn

command:
  description: Generate a new file with a hello message
  options:
    #
    - name: greeting
      description: who or what to say hello to
      dataType: string
      defaultValue: World
      inputType: text     # TEXT
```

的内容hello.yamlspring-doc.cadn.net.cn

actions:
  - generate:
      to: hello.txt
      text: Hello {{greeting}} on {{os-name}}.

了解 actions 文件

为了帮助您了解如何使用 YAML 语法创建作文件,本节将介绍示例的每一行进行说明:spring-doc.cadn.net.cn

法典 解释。

行动:spring-doc.cadn.net.cn

将所有作组合在一起。spring-doc.cadn.net.cn

生成:spring-doc.cadn.net.cn

要执行的作类型。例如,此作类型会生成文件。spring-doc.cadn.net.cn

自:spring-doc.cadn.net.cn

在文件系统中生成文件的位置。spring-doc.cadn.net.cn

发短信:spring-doc.cadn.net.cn

要生成的文件的内容。spring-doc.cadn.net.cn

运行用户定义的命令

$ spring hello create --greeting World!
Generated /home/testing/rest-service/hello.txt

$ cat hello.txt
Hello World! on Linux.

后续步骤