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:
Janne Valkealahti
2022-07-21 21:24:41 +01:00
parent 416700b10b
commit 690d1d2e62
3 changed files with 128 additions and 0 deletions

View File

@@ -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<String> getNames() {
return Arrays.asList(name.split(" "));
}
public List<String> getAliases() {
return this.aliases;
}

View File

@@ -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()