|
| 1 | +[[built-in-commands-help]] |
| 2 | +==== Help |
| 3 | + |
| 4 | +Running a shell application often implies that the user is in a graphically limited |
| 5 | +environment. Also, while we are nearly always connected in the era of mobile phones, |
| 6 | +accessing a web browser or any other rich UI application (such as a PDF viewer) may not always |
| 7 | +be possible. This is why it is important that the shell commands are correctly self-documented, and this is where the `help` |
| 8 | +command comes in. |
| 9 | + |
| 10 | +Typing `help` + `ENTER` lists all the commands known to the shell (including <<dynamic-command-availability,unavailable>> commands) |
| 11 | +and a short description of what they do, similar to the following: |
| 12 | + |
| 13 | +==== |
| 14 | +[source, bash] |
| 15 | +---- |
| 16 | +my-shell:>help |
| 17 | +AVAILABLE COMMANDS |
| 18 | +
|
| 19 | +Built-In Commands |
| 20 | + exit: Exit the shell. |
| 21 | + help: Display help about available commands |
| 22 | + stacktrace: Display the full stacktrace of the last error. |
| 23 | + clear: Clear the shell screen. |
| 24 | + quit: Exit the shell. |
| 25 | + history: Display or save the history of previously run commands |
| 26 | + completion bash: Generate bash completion script |
| 27 | + version: Show version info |
| 28 | + script: Read and execute commands from a file. |
| 29 | +---- |
| 30 | +==== |
| 31 | + |
| 32 | +Typing `help <command>` shows more detailed information about a command, including the available parameters, their |
| 33 | +type, whether they are mandatory or not, and other details. |
| 34 | + |
| 35 | +The following listing shows the `help` command applied to itself: |
| 36 | + |
| 37 | +==== |
| 38 | +[source, bash] |
| 39 | +---- |
| 40 | +my-shell:>help help |
| 41 | +NAME |
| 42 | + help - Display help about available commands |
| 43 | +
|
| 44 | +SYNOPSIS |
| 45 | + help --command String |
| 46 | +
|
| 47 | +OPTIONS |
| 48 | + --command or -C String |
| 49 | + The command to obtain help for. |
| 50 | + [Optional] |
| 51 | +---- |
| 52 | +==== |
| 53 | + |
| 54 | +Help is templated and can be customized if needed. Settings are under `spring.shell.command.help` where you can use |
| 55 | +`enabled` to disable command, `grouping-mode` taking `group` or `flat` if you want to hide groups by flattening |
| 56 | +a structure, `command-template` to define your template for output of a command help, `commands-template` to define |
| 57 | +output of a command list. |
| 58 | + |
| 59 | +If `spring.shell.command.help.grouping-mode=flat` is set, then help would show: |
| 60 | + |
| 61 | +==== |
| 62 | +[source, bash] |
| 63 | +---- |
| 64 | +my-shell:>help help |
| 65 | +AVAILABLE COMMANDS |
| 66 | +
|
| 67 | +exit: Exit the shell. |
| 68 | +help: Display help about available commands |
| 69 | +stacktrace: Display the full stacktrace of the last error. |
| 70 | +clear: Clear the shell screen. |
| 71 | +quit: Exit the shell. |
| 72 | +history: Display or save the history of previously run commands |
| 73 | +completion bash: Generate bash completion script |
| 74 | +version: Show version info |
| 75 | +script: Read and execute commands from a file. |
| 76 | +---- |
| 77 | +==== |
| 78 | + |
| 79 | +Output from `help` and `help <commmand>` are both templated with a default implementation |
| 80 | +which can be changed. |
| 81 | + |
| 82 | +Option `spring.shell.command.help.commands-template` defaults to |
| 83 | +`classpath:template/help-commands-default.stg` and is passed `GroupsInfoModel` |
| 84 | +as a model. |
| 85 | + |
| 86 | +Option `spring.shell.command.help.command-template` defaults to |
| 87 | +`classpath:template/help-command-default.stg` and is passed `CommandInfoModel` |
| 88 | +as a model. |
| 89 | + |
| 90 | +[[groupsinfomodel-variables]] |
| 91 | +.GroupsInfoModel Variables |
| 92 | +|=== |
| 93 | +|Key |Description |
| 94 | + |
| 95 | +|`showGroups` |
| 96 | +|`true` if showing groups is enabled. Otherwise, false. |
| 97 | + |
| 98 | +|`groups` |
| 99 | +|The commands variables (see <<groupcommandinfomodel-variables>>). |
| 100 | + |
| 101 | +|`commands` |
| 102 | +|The commands variables (see <<commandinfomodel-variables>>). |
| 103 | + |
| 104 | +|`hasUnavailableCommands` |
| 105 | +|`true` if there is unavailable commands. Otherwise, false. |
| 106 | +|=== |
| 107 | + |
| 108 | +[[groupcommandinfomodel-variables]] |
| 109 | +.GroupCommandInfoModel Variables |
| 110 | +|=== |
| 111 | +|Key |Description |
| 112 | + |
| 113 | +|`group` |
| 114 | +|The name of a group, if set. Otherwise, empty. |
| 115 | + |
| 116 | +|`commands` |
| 117 | +|The commands, if set. Otherwise, empty. Type is a multi value, see <<commandinfomodel-variables>>. |
| 118 | +|=== |
| 119 | + |
| 120 | +[[commandinfomodel-variables]] |
| 121 | +.CommandInfoModel Variables |
| 122 | +|=== |
| 123 | +|Key |Description |
| 124 | + |
| 125 | +|`name` |
| 126 | +|The name of a command, if set. Otherwise, null. Type is string and contains full command. |
| 127 | + |
| 128 | +|`names` |
| 129 | +|The names of a command, if set. Otherwise, null. Type is multi value essentially `name` splitted. |
| 130 | + |
| 131 | +|`aliases` |
| 132 | +|The possible aliases, if set. Type is multi value with strings. |
| 133 | + |
| 134 | +|`description` |
| 135 | +|The description of a command, if set. Otherwise, null. |
| 136 | + |
| 137 | +|`parameters` |
| 138 | +|The parameters variables, if set. Otherwise empty. Type is a multi value, see <<commandparameterinfomodel-variables>>. |
| 139 | + |
| 140 | +|`availability` |
| 141 | +|The availability variables (see <<commandavailabilityinfomodel-variables>>). |
| 142 | +|=== |
| 143 | + |
| 144 | +[[commandparameterinfomodel-variables]] |
| 145 | +.CommandParameterInfoModel Variables |
| 146 | +|=== |
| 147 | +|Key |Description |
| 148 | + |
| 149 | +|`type` |
| 150 | +|The type of a parameter if set. Otherwise, null. |
| 151 | + |
| 152 | +|`arguments` |
| 153 | +|The arguments, if set. Otherwise, null. Type is multi value with strings. |
| 154 | + |
| 155 | +|`required` |
| 156 | +|`true` if required. Otherwise, false. |
| 157 | + |
| 158 | +|`description` |
| 159 | +|The description of a parameter, if set. Otherwise, null. |
| 160 | + |
| 161 | +|`defaultValue` |
| 162 | +|The default value of a parameter, if set. Otherwise, null. |
| 163 | + |
| 164 | +|`hasDefaultValue` |
| 165 | +|`true` if defaultValue exists. Otherwise, false. |
| 166 | +|=== |
| 167 | + |
| 168 | +[[commandavailabilityinfomodel-variables]] |
| 169 | +.CommandAvailabilityInfoModel Variables |
| 170 | +|=== |
| 171 | +|Key |Description |
| 172 | + |
| 173 | +|`available` |
| 174 | +|`true` if available. Otherwise, false. |
| 175 | + |
| 176 | +|`reason` |
| 177 | +|The reason if not available if set. Otherwise, null. |
| 178 | +|=== |
0 commit comments