帮助
运行 Shell 应用程序通常意味着用户处于图形界面受限的环境中。此外,虽然在移动电话时代我们几乎总是处于连接状态,但访问 Web 浏览器或任何其他丰富的 UI 应用程序(例如 PDF 阅读器)可能并不总是可行。这就是 Shell 命令必须正确地进行自我文档化的原因,而这正是 help
命令的作用所在。
键入 help
+ ENTER
将列出 Shell 已知的全部命令(包括不可用的命令)以及它们的功能简述,类似于以下内容:
my-shell:>help
AVAILABLE COMMANDS
Built-In Commands
exit: Exit the shell.
help: Display help about available commands
stacktrace: Display the full stacktrace of the last error.
clear: Clear the shell screen.
quit: Exit the shell.
history: Display or save the history of previously run commands
completion bash: Generate bash completion script
version: Show version info
script: Read and execute commands from a file.
键入 help <command>
将显示有关某个命令的更详细信息,包括可用的参数、它们的类型、它们是否是强制性的以及其他详细信息。
以下列表显示了应用于自身 help
命令:
my-shell:>help help
NAME
help - Display help about available commands
SYNOPSIS
help --command String
OPTIONS
--command or -C String
The command to obtain help for.
[Optional]
帮助是使用模板生成的,如果需要,可以自定义。设置位于 spring.shell.command.help
下,您可以在其中使用 enabled
禁用命令,grouping-mode
使用 group
或 flat
如果您想通过扁平化结构隐藏组,command-template
定义命令帮助输出的模板,commands-template
定义命令列表的输出。
如果设置了 spring.shell.command.help.grouping-mode=flat
,则帮助将显示:
my-shell:>help help
AVAILABLE COMMANDS
exit: Exit the shell.
help: Display help about available commands
stacktrace: Display the full stacktrace of the last error.
clear: Clear the shell screen.
quit: Exit the shell.
history: Display or save the history of previously run commands
completion bash: Generate bash completion script
version: Show version info
script: Read and execute commands from a file.
来自 help
和 help <commmand>
的输出都使用默认实现的模板进行生成,该模板可以更改。
选项 spring.shell.command.help.commands-template
默认为 classpath:template/help-commands-default.stg
,并传递 GroupsInfoModel
作为模型。
选项 spring.shell.command.help.command-template
默认为 classpath:template/help-command-default.stg
,并传递 CommandInfoModel
作为模型。
键 | 描述 |
---|---|
|
如果启用了显示组,则为 |
|
命令变量(请参阅GroupCommandInfoModel 变量)。 |
|
命令变量(请参阅CommandInfoModel 变量)。 |
|
如果存在不可用命令,则为 |
键 | 描述 |
---|---|
|
如果设置了组名称,则为组名称。否则为空。 |
|
如果设置了命令,则为命令。否则为空。类型为多值,请参阅CommandInfoModel 变量。 |
键 | 描述 |
---|---|
|
如果设置了命令名称,则为命令名称。否则为 null。类型为字符串,包含完整命令。 |
|
如果设置了命令名称,则为命令名称。否则为 null。类型为多值,本质上是 |
|
如果设置了可能的别名,则为可能的别名。类型为包含字符串的多值。 |
|
如果设置了命令描述,则为命令描述。否则为 null。 |
|
如果设置了参数变量,则为参数变量。否则为空。类型为多值,请参阅CommandParameterInfoModel 变量。 |
|
可用性变量(请参阅CommandAvailabilityInfoModel 变量)。 |
键 | 描述 |
---|---|
|
如果设置了参数类型,则为参数类型。否则为 null。 |
|
如果设置了参数,则为参数。否则为 null。类型为包含字符串的多值。 |
|
如果需要,则为 |
|
如果设置了参数描述,则为参数描述。否则为 null。 |
|
如果设置了参数的默认值,则为参数的默认值。否则为 null。 |
|
如果存在 defaultValue,则为 |
键 | 描述 |
---|---|
|
如果可用,则为 |
|
如果不可用,则为原因(如果设置)。否则为 null。 |