Action Files

Action files power user defined commands. These files are written in YAML format and are stored in the directory that defines the command.spring-doc.cn

See the documentation on Action file Structure for more information on the directory structure for user-defined commands.spring-doc.cn

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.spring-doc.cn

There can be multiple action files in a directory, and they are evaluated in alphabetical order.spring-doc.cn

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.spring-doc.cn

The list of actions are:spring-doc.cn

  • generate - Create a new file.spring-doc.cn

  • inject - Inject text into a specific location in an existing file.spring-doc.cn

  • inject-maven-dependency - Append a dependency entry to the current pom.xml file.spring-doc.cn

  • inject-maven-plugin - Append a Maven plugin entry to the current pom.xml filespring-doc.cn

  • inject-maven-dependency-management - Append a dependency management entry to the current pom.xml file.spring-doc.cn

  • inject-maven-repository - Append a repository entry to the current pom.xml filespring-doc.cn

  • inject-properties - Append properties to a Java properties file.spring-doc.cn

  • exec - Run another program.spring-doc.cn

An Introductory Example

The CLI command new command creates a simple user-defined command that we can use to demonstrate the components of an actions file.spring-doc.cn

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

The directory structure isspring-doc.cn

$ tree .spring
.spring
└── commands
    └── hello
        └── create
            ├── command.yaml
            └── 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.spring-doc.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
```

The content of hello.yaml isspring-doc.cn

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

Understanding the actions file

To help you understand how YAML syntax is used to create an actions file, this section explains each line of the introduction’s example:spring-doc.cn

Code Explanation.

actions:spring-doc.cn

Groups together all the actions.spring-doc.cn

generate:spring-doc.cn

The type of action to take. For example, this action type generates files.spring-doc.cn

to:spring-doc.cn

Where in the file system to generate the file.spring-doc.cn

text:spring-doc.cn

The content of the file to generate.spring-doc.cn

Running the User-defined Command

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

$ cat hello.txt
Hello World! on Linux.

Next Steps