Action Files
动作文件为 user defined commands 提供动力。这些文件以 YAML 格式编写,并存储在定义命令的目录中。
Action files power user defined commands. These files are written in YAML format and are stored in the directory that defines the command.
有关用户自定义命令的目录结构的更多信息,请参阅 Action file Structure 中的文档。
See the documentation on Action file Structure for more information on the directory structure for user-defined commands.
每个文件都包含一系列操作,这些操作将按它们在文件中定义的顺序运行。操作执行一个通常是必需的任务,以帮助开发人员向他们当前的项目中添加或修改代码和配置。操作可以运行另一个可执行应用程序,这有助于自动执行开发任务,例如使用供应商的 CLI 应用程序进行部署。
Each file contains a series of actions that are run in the order in which they are defined in the file. An action performs a task that is commonly needed to help developers add or modify code and configuration to their current project. An action can run another executable application, which helps automate development tasks, such as deployment using a vendor’s CLI application.
一个目录中可以有多个 Action 文件,并且会按字母顺序对其进行评估。
There can be multiple action files in a directory, and they are evaluated in alphabetical order.
评估顺序可能会在未来版本中发生变化。 |
The order of evaluation may change in a future release. |
目前,仅有少数几种操作,但已有许多原型的操作即将推出。
Currently, only a few actions exist, but many more have been prototypes and will be available soon.
操作的列表如下:
The list of actions are:
-
generate - Create a new file.
-
inject - Inject text into a specific location in an existing file.
-
inject-maven-dependency - Append a dependency entry to the current pom.xml file.
-
inject-maven-plugin - Append a Maven plugin entry to the current pom.xml file
-
inject-maven-dependency-management - Append a dependency management entry to the current pom.xml file.
-
inject-maven-repository - Append a repository entry to the current pom.xml file
-
inject-properties - Append properties to a Java properties file.
-
exec - Run another program.
An Introductory Example
CLI command new
命令创建一个简单的用户定义命令,我们可以使用此命令演示 Action 文件的组件。
The CLI command new
command creates a simple user-defined command that we can use to demonstrate the components of an actions file.
spring command new --commandName hello --subCommandName create
Created user defined command /home/testing/rest-service/.spring/commands/hello/create
目录结构为:
The directory structure is
$ tree .spring
.spring
└── commands
└── hello
└── create
├── command.yaml
└── hello.yaml
command.yaml
的内容(如下所示)定义了一个名为 greeting
的命令行参数。此参数用于 hello.yaml
操作文件中。
The content of command.yaml
, shown below, defines a command line argument named greeting
.
This argument is used in the hello.yaml
action file.
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
的内容为:
The content of hello.yaml
is
actions:
- generate:
to: hello.txt
text: Hello {{greeting}} on {{os-name}}.
Understanding the actions file
为帮助您理解如何使用 YAML 语法创建 Action 文件,本部分将解释每行简介示例:
To help you understand how YAML syntax is used to create an actions file, this section explains each line of the introduction’s example:
Code | Explanation. |
---|---|
actions: |
Groups together all the actions. |
generate: |
The type of action to take. For example, this action type generates files. |
to: |
Where in the file system to generate the file. |
text: |
The content of the file to generate. |