幫助

執行 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.