Key Concepts

Spring CLI 依赖于许多关键概念,这些概念出现在整个项目中:

Spring CLI relies on a number of key concepts, which appear throughout the project:

Project

项目:一个托管在 GitHub 或 GitLab 中的“普通旧 Java 项目”。项目与 CLI 绑定在一起,以便一个简单的名称可以引用它们。

Project: A "Plain Old Java Project" hosted in GitHub or GitLab. Projects are registered with the CLI so that a simple name can refer to them.

例如,如果你使用名称“jpa”注册一个使用 Spring Data JPA 的项目的 GitHub URL,则可以通过调用命令 boot new my-jpa-app jpa 从该项目创建一个新项目。同样,你可以通过调用 boot add jpa 命令,将 JPA 功能添加到现有项目中。

For example, if you register the GitHub URL of a project that uses Spring Data JPA with a name of ‘jpa’, you can create a new project from that one by invoking the command boot new my-jpa-app jpa command. Similarly, you can add JPA functionality to an existing project by invoking the boot add jpa command.

与项目相关的命令包括 project listproject addproject remove

The commands related to projects are project list, project add, and project remove.

Project Catalog

项目目录:项目目录是一个共享一个主题的项目集合。

Project Catalog: The Project Catalog is a collection of projects that share a common theme.

在使用 boot newboot add 命令时,在将目录与 CLI 关联后,将可以立即获取这些项目。该目录是一个名为 project-catalog.yaml 的 YAML 文件。它包含一个项目存储库 URL 列表和一个关联的名称。目录托管在 GitHub 或 GitLab 上

After registering a catalog with the CLI, the projects are readily available when using the boot new and boot add commands. The catalog is a YAML file with a name of project-catalog.yaml. It contains a list of project repository URLs and an associated name. The catalog is hosted on GitHub or GitLab

与项目目录相关的命令包括 catalog listcatalog addcatalog remove

The commands related to project catalogs are catalog list, catalog add, and catalog remove

User Defined Commands

命令:这些是通过声明定义的命令,允许你添加或修改代码和配置文件。

Commands: These are declaratively defined commands that let you add or modify code and configuration files.

你还可以运行任意可执行文件,以执行开发工作流中通常发生的任何任意任务。用户定义的命令集成到 CLI 中,并且与内置命令看起来相同。

You can also run arbitrary executables to perform any arbitrary task that commonly occurs in your development workflow. User-defined commands are integrated into the CLI and appear the same as the built-in commands.

用户定义的命令具有三个部分:command namesub-command nameoptions。命令名称和子命令名称通过使用目录结构约定来定义。

A user-defined command has three parts: the command name, the sub-command name, and the options. The command name and sub-command name are defined by using a directory structure convention.

例如,要创建一个命令名称为 controller 和子命令名称为 new 的新用户定义命令,请设置以下目录结构:

For example, to create a new user-defined command with a command name of controller and a sub-command name of new, make the following directory structure:

.spring/commands/controller/new

在这个目录中,你可以创建一个名为 command.yaml 的文件,该文件定义了该命令的说明、选项和默认值。此目录(和子目录)包含动作文件,这些文件定义了在项目上执行的动作。

In this directory, you can have one file named command.yaml that defines the command’s description, options, and default values. This directory (and subdirectories) contain action files that define the actions to take on the project.

Action Files

Action Files: 它们定义了可以在项目上执行的操作。

Action Files: These define the actions that can be taken on a project.

Roles

在你的 CLI 中,角色提供了一种方法来组织和在用户自定义命令中重用变量。

In your CLI, roles provide a way to organize and reuse variables across user-defined commands.

Spring CLI 包含了一个总是存在的默认未命名角色。此外,角色可以与特定名称相关联,以进一步区分其用途和用法。这些角色存储为与 .spring/commands 目录并列的 .spring/roles 目录中的 YAML 文件。

The Spring CLI includes a default, unnamed role that is always present. Also, roles can be associated with specific names to further differentiate their purpose and usage. These roles are stored as YAML files within the .spring/roles directory, which is located alongside the .spring/commands directory.

这些角色允许你定义可在操作文件中访问的变量,提供了一种在命令之间共享数据的方法。

These roles let you define variables that are accessible in an action file, providing a way to share data between commands.

你还可以使用角色为命令行选项提供值。如果命令行选项没有指定值,并且已经定义了与命令选项同名的角色变量,则命令会为该特定命令选项使用角色变量的值。

You can also use roles to supply values for command line options. If a command-line option does not have a specified value and a role variable has been defined with the same name as the command option, the command uses the value of the role variable for that specific command option.

与项目相关的一些常见角色命令为 role addrole removerole set

Some common role commands related to projects are role add, role remove, and role set