幫助
執行 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(取值 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 <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 作為模型。
| 鍵 | 描述 |
|---|---|
|
如果顯示組已啟用,則為 |
|
命令變數(請參閱GroupCommandInfoModel 變數)。 |
|
命令變數(請參閱CommandInfoModel 變數)。 |
|
如果存在不可用命令,則為 |
| 鍵 | 描述 |
|---|---|
|
組的名稱,如果已設定。否則為空。型別為字串。 |
|
命令,如果已設定。否則為空。型別為多值,請參閱CommandInfoModel 變數。 |
| 鍵 | 描述 |
|---|---|
|
命令的名稱,如果已設定。否則為 null。型別為字串,包含完整命令。 |
|
命令的名稱,如果已設定。否則為 null。型別為多值,本質上是 |
|
可能的別名,如果已設定。型別為包含字串的多值。 |
|
命令的描述,如果已設定。否則為 null。 |
|
引數變數,如果已設定。否則為空。型別為多值,請參閱CommandParameterInfoModel 變數。 |
|
可用性變數(請參閱CommandAvailabilityInfoModel 變數)。 |
| 鍵 | 描述 |
|---|---|
|
引數的型別,如果已設定。否則為 null。 |
|
引數,如果已設定。否則為 null。型別為包含字串的多值。 |
|
如果必需,則為 |
|
引數的描述,如果已設定。否則為 null。 |
|
引數的預設值,如果已設定。否則為 null。 |
|
如果 defaultValue 存在,則為 |
| 鍵 | 描述 |
|---|---|
|
如果可用,則為 |
|
如果不可用,則為原因(如果已設定)。否則為 null。 |