Alias
为命令定义 alias 是可行的。这对于您想要创建命令的较短版本或遍历完整的命令重命名,同时暂时保留旧命令的情况很方便。
It is possible to define an alias for a command. This is convenient for cases where you want to create a shorter version of a command or going through a complete command rename while keeping old one temporarily in place.
alias 的格式与 command 略有不同。当 command 被定义为数组时,它被连接成一个单独的命令。当 alias 被定义为数组时,它用于创建单独的别名。
Format for alias is slighly different than a command. When command is defined as an array it’s concatenated together into a single command. When alias is defined as an array it’s used to create a separate aliases.
带有普通 CommandRegistration
的别名既简单又清晰,因为您可以确切地得到定义的内容,因为它没有“魔力”。
Aliases with a plain CommandRegistration
is simple and clear as you
get exactly what you define as there’s no "magic" in it.
Unresolved include directive in modules/ROOT/pages/commands/alias.adoc - include::../../../../src/test/java/org/springframework/shell/docs/CommandRegistrationAliasSnippets.java[]
使用 @Command
注解定义别名稍微复杂一些,因为它可以在类和方法级别上存在。以下是它如何工作的示例。
Defining alias with @Command
annotation is a bit more involved as it
can exist on a both class and method levels. Here are examples how it
works.
仅在方法上定义别名会提供 myalias。
Alias just on a method gives you myalias.
Unresolved include directive in modules/ROOT/pages/commands/alias.adoc - include::../../../../src/test/java/org/springframework/shell/docs/CommandRegistrationAliasSnippets.java[]
或 myalias1 和 myalias2(如果定义为数组)。
Or myalias1 and myalias2 if defined as an array.
Unresolved include directive in modules/ROOT/pages/commands/alias.adoc - include::../../../../src/test/java/org/springframework/shell/docs/CommandRegistrationAliasSnippets.java[]
仅在类级别上的别名不起作用,因为它只是 method level if defined 上注解的指令。
Alias only on a class level does nothing as it’s simply an instruction for annotation on a method level if defined.
Unresolved include directive in modules/ROOT/pages/commands/alias.adoc - include::../../../../src/test/java/org/springframework/shell/docs/CommandRegistrationAliasSnippets.java[]
类和方法级别的别名将两者结合在一起,其中类级别作为前缀,方法级别作为别名的组合。类级别的别名通常与 command 前缀一起使用,以将别名保留在同一命令级别。
Alias on both class and method level combines those two together where class level works as an prefix and method level as combination of aliases. Alias on a class level is usually used together with a command prefix to keep aliases on a same command level.
在这里,您将获得别名 myalias1 myalias2。
Here you’d get alias myalias1 myalias2.
Unresolved include directive in modules/ROOT/pages/commands/alias.adoc - include::../../../../src/test/java/org/springframework/shell/docs/CommandRegistrationAliasSnippets.java[]
在方法级别上有一种特殊的格式,即 empty string,它允许您创建别名,但它只使用类级别的前缀。
On a method level there’s a special format, that being an empty string which allows you to create an alias but it only uses prefix from a class level.
在这里,您将获得别名 myalias1。
Here you’d get alias myalias1.
Unresolved include directive in modules/ROOT/pages/commands/alias.adoc - include::../../../../src/test/java/org/springframework/shell/docs/CommandRegistrationAliasSnippets.java[]