Add commands as list in help templating
- Add getNames method. - Add docs for templating info and fields to help. - Fixes #480
This commit is contained in:
@@ -79,6 +79,107 @@ script: Read and execute commands from a file.
|
|||||||
----
|
----
|
||||||
====
|
====
|
||||||
|
|
||||||
|
Output from `help` and `help <commmand>` 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 <<groupcommandinfomodel-variables>>).
|
||||||
|
|
||||||
|
|`commands`
|
||||||
|
|The commands variables (see <<commandinfomodel-variables>>).
|
||||||
|
|
||||||
|
|`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]]
|
||||||
|
.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 <<commandparameterinfomodel-variables>>.
|
||||||
|
|
||||||
|
|`availability`
|
||||||
|
|The availability variables (see <<commandavailabilityinfomodel-variables>>).
|
||||||
|
|===
|
||||||
|
|
||||||
|
[[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
|
==== Clear
|
||||||
The `clear` command does what you would expect and clears the screen, resetting the prompt
|
The `clear` command does what you would expect and clears the screen, resetting the prompt
|
||||||
in the top left corner.
|
in the top left corner.
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.shell.standard.commands;
|
package org.springframework.shell.standard.commands;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
@@ -98,6 +99,10 @@ class CommandInfoModel {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getNames() {
|
||||||
|
return Arrays.asList(name.split(" "));
|
||||||
|
}
|
||||||
|
|
||||||
public List<String> getAliases() {
|
public List<String> getAliases() {
|
||||||
return this.aliases;
|
return this.aliases;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,28 @@ public class CommandInfoModelTests {
|
|||||||
assertThat(cim.getName()).isEqualTo("main1");
|
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
|
@Test
|
||||||
void hasGivenDescription() {
|
void hasGivenDescription() {
|
||||||
CommandRegistration r1 = CommandRegistration.builder()
|
CommandRegistration r1 = CommandRegistration.builder()
|
||||||
|
|||||||
Reference in New Issue
Block a user