diff --git a/spring-shell-docs/src/main/asciidoc/using-shell-components-builtin.adoc b/spring-shell-docs/src/main/asciidoc/using-shell-components-builtin.adoc index cdb0474f..c8e2f3c8 100644 --- a/spring-shell-docs/src/main/asciidoc/using-shell-components-builtin.adoc +++ b/spring-shell-docs/src/main/asciidoc/using-shell-components-builtin.adoc @@ -79,6 +79,107 @@ script: Read and execute commands from a file. ---- ==== +Output from `help` and `help ` are both templated with a default implementation +which can be changed. + +Option `spring.shell.command.help.commands-template` defaults to +`classpath:template/help-commands-default.stg` and is passed `GroupsInfoModel` +as a model. + +Option `spring.shell.command.help.command-template` defaults to +`classpath:template/help-command-default.stg` and is passed `CommandInfoModel` +as a model. + +[[groupsinfomodel-variables]] +.GroupsInfoModel Variables +|=== +|Key |Description + +|`showGroups` +|`true` if showing groups is enabled. Otherwise, false. + +|`groups` +|The commands variables (see <>). + +|`commands` +|The commands variables (see <>). + +|`hasUnavailableCommands` +|`true` if there is unavailable commands. Otherwise, false. +|=== + +[[groupcommandinfomodel-variables]] +.GroupCommandInfoModel Variables +|=== +|Key |Description + +|`group` +|The name of a group, if set. Otherwise, empty. + +|`commands` +|The commands, if set. Otherwise, empty. Type is a multi value, see <>. +|=== + +[[commandinfomodel-variables]] +.CommandInfoModel Variables +|=== +|Key |Description + +|`name` +|The name of a command, if set. Otherwise, null. Type is string and contains full command. + +|`names` +|The names of a command, if set. Otherwise, null. Type is multi value essentially `name` splitted. + +|`aliases` +|The possible aliases, if set. Type is multi value with strings. + +|`description` +|The description of a command, if set. Otherwise, null. + +|`parameters` +|The parameters variables, if set. Otherwise empty. Type is a multi value, see <>. + +|`availability` +|The availability variables (see <>). +|=== + +[[commandparameterinfomodel-variables]] +.CommandParameterInfoModel Variables +|=== +|Key |Description + +|`type` +|The type of a parameter if set. Otherwise, null. + +|`arguments` +|The arguments, if set. Otherwise, null. Type is multi value with strings. + +|`required` +|`true` if required. Otherwise, false. + +|`description` +|The description of a parameter, if set. Otherwise, null. + +|`defaultValue` +|The default value of a parameter, if set. Otherwise, null. + +|`hasDefaultValue` +|`true` if defaultValue exists. Otherwise, false. +|=== + +[[commandavailabilityinfomodel-variables]] +.CommandAvailabilityInfoModel Variables +|=== +|Key |Description + +|`available` +|`true` if available. Otherwise, false. + +|`reason` +|The reason if not available if set. Otherwise, null. +|=== + ==== Clear The `clear` command does what you would expect and clears the screen, resetting the prompt in the top left corner. diff --git a/spring-shell-standard-commands/src/main/java/org/springframework/shell/standard/commands/CommandInfoModel.java b/spring-shell-standard-commands/src/main/java/org/springframework/shell/standard/commands/CommandInfoModel.java index 2fa64083..2af7d6ba 100644 --- a/spring-shell-standard-commands/src/main/java/org/springframework/shell/standard/commands/CommandInfoModel.java +++ b/spring-shell-standard-commands/src/main/java/org/springframework/shell/standard/commands/CommandInfoModel.java @@ -15,6 +15,7 @@ */ package org.springframework.shell.standard.commands; +import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -98,6 +99,10 @@ class CommandInfoModel { return name; } + public List getNames() { + return Arrays.asList(name.split(" ")); + } + public List getAliases() { return this.aliases; } diff --git a/spring-shell-standard-commands/src/test/java/org/springframework/shell/standard/commands/CommandInfoModelTests.java b/spring-shell-standard-commands/src/test/java/org/springframework/shell/standard/commands/CommandInfoModelTests.java index 760e78de..3da517af 100644 --- a/spring-shell-standard-commands/src/test/java/org/springframework/shell/standard/commands/CommandInfoModelTests.java +++ b/spring-shell-standard-commands/src/test/java/org/springframework/shell/standard/commands/CommandInfoModelTests.java @@ -35,6 +35,28 @@ public class CommandInfoModelTests { assertThat(cim.getName()).isEqualTo("main1"); } + @Test + void hasGivenNames() { + CommandRegistration r1 = CommandRegistration.builder() + .command("main1") + .withTarget() + .consumer(ctx -> {}) + .and() + .build(); + CommandInfoModel cim = CommandInfoModel.of("main1", r1); + assertThat(cim.getNames()).containsExactly("main1"); + + r1 = CommandRegistration.builder() + .command("main1 sub1") + .withTarget() + .consumer(ctx -> {}) + .and() + .build(); + + cim = CommandInfoModel.of("main1 sub1", r1); + assertThat(cim.getNames()).containsExactly("main1", "sub1"); + } + @Test void hasGivenDescription() { CommandRegistration r1 = CommandRegistration.builder()