操作文件

Action 文件为 用户自定义命令 提供支持。 这些文件采用 YAML 格式编写,并存储在定义该命令的目录中。spring-doc.cadn.net.cn

有关用户定义命令的目录结构的更多信息,请参阅 Action 文件结构 文档。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

一个入门示例

CLI command new 命令创建一个简单的用户自定义命令,可用于演示操作文件的组成部分。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.yaml 的内容是spring-doc.cadn.net.cn

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

理解 actions 文件

为了帮助您理解如何使用 YAML 语法创建操作文件,本节将逐行解释引言中的示例:spring-doc.cadn.net.cn

代码 Explanation.

操作:spring-doc.cadn.net.cn

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

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

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

to: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.

下一步