跳到主要内容

帮助

QWen Max 中英对照 Help

运行 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.
bash

输入 help <命令> 会显示关于该命令的更详细信息,包括可用参数、参数类型、是否必填以及其他细节。

以下列表展示了应用于自身的 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]
bash

帮助是模板化的,可以根据需要进行自定义。设置在 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.
bash

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

表 1. GroupsInfoModel 变量

KeyDescription
showGroups如果启用了显示组,则为 true。否则为 false
groups命令变量(参见 GroupCommandInfoModel 变量)。
commands命令变量(参见 CommandInfoModel 变量)。
hasUnavailableCommands如果有不可用的命令,则为 true。否则为 false

表 2. GroupCommandInfoModel 变量

说明
group如果设置,为组的名称。否则,为空。
commands如果设置,为命令。否则,为空。类型是多值,参见 CommandInfoModel 变量

表 3. CommandInfoModel 变量

Key描述
name命令的名称(如果设置)。否则为 null。类型是字符串,包含完整命令。
names命令的名称(如果设置)。否则为 null。类型是多值,本质上是 name 的拆分。
aliases可能的别名(如果设置)。类型是多值字符串。
description命令的描述(如果设置)。否则为 null。
parameters参数变量(如果设置)。否则为空。类型是多值,参见 CommandParameterInfoModel 变量
availability可用性变量(参见 CommandAvailabilityInfoModel 变量)。

表 4. CommandParameterInfoModel 变量

Key描述
type如果设置了参数类型,则为该类型。否则,为 null。
arguments如果设置了参数,则为这些参数。否则,为 null。类型是包含字符串的多值。
required如果必填,则为 true。否则,为 false。
description如果设置了参数描述,则为该描述。否则,为 null。
defaultValue如果设置了参数的默认值,则为该默认值。否则,为 null。
hasDefaultValue如果存在 defaultValue,则为 true。否则,为 false。

表 5. CommandAvailabilityInfoModel 变量

说明
available如果可用,则为 true。否则,为 false
reason如果设置了不可用的原因,则显示该原因。否则,为 null。