帮助

运行 shell 应用程序通常意味着用户处于图形受限的环境中。这就是为什么 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(取值 groupflat,如果您想通过扁平化结构隐藏组),使用 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.

helphelp <command> 的输出都使用默认实现进行模板化,该实现可以更改。

选项 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 作为模型。

表 1. GroupsInfoModel 变量
描述

showGroups

如果显示组已启用,则为 true。否则为 false。

groups

命令变量(请参阅GroupCommandInfoModel 变量)。

commands

命令变量(请参阅CommandInfoModel 变量)。

hasUnavailableCommands

如果存在不可用命令,则为 true。否则为 false。

表 2. GroupCommandInfoModel 变量
描述

group

组的名称,如果已设置。否则为空。类型为字符串。

commands

命令,如果已设置。否则为空。类型为多值,请参阅CommandInfoModel 变量

表 3. CommandInfoModel 变量
描述

name

命令的名称,如果已设置。否则为 null。类型为字符串,包含完整命令。

names

命令的名称,如果已设置。否则为 null。类型为多值,本质上是 name 的拆分。

aliases

可能的别名,如果已设置。类型为包含字符串的多值。

描述

命令的描述,如果已设置。否则为 null。

parameters

参数变量,如果已设置。否则为空。类型为多值,请参阅CommandParameterInfoModel 变量

availability

可用性变量(请参阅CommandAvailabilityInfoModel 变量)。

表 4. CommandParameterInfoModel 变量
描述

类型

参数的类型,如果已设置。否则为 null。

arguments

参数,如果已设置。否则为 null。类型为包含字符串的多值。

required

如果必需,则为 true。否则为 false。

描述

参数的描述,如果已设置。否则为 null。

defaultValue

参数的默认值,如果已设置。否则为 null。

hasDefaultValue

如果 defaultValue 存在,则为 true。否则为 false。

表 5. CommandAvailabilityInfoModel 变量
描述

available

如果可用,则为 true。否则为 false。

reason

如果不可用,则为原因(如果已设置)。否则为 null。

© . This site is unofficial and not affiliated with VMware.