Change help to description in command registration

- Fixes #421
This commit is contained in:
Janne Valkealahti
2022-05-18 08:59:57 +01:00
parent c7d3eb15b4
commit baf8346063
10 changed files with 58 additions and 73 deletions

View File

@@ -271,7 +271,7 @@ public class Shell {
return new CompletionProposal(command)
.dontQuote(true)
.category("Available commands")
.description(registration.getHelp());
.description(registration.getDescription());
}
/**

View File

@@ -56,13 +56,6 @@ public interface CommandRegistration {
*/
InteractionMode getInteractionMode();
/**
* Get help for a command.
*
* @return the help
*/
String getHelp();
/**
* Get group for a command.
*
@@ -382,12 +375,12 @@ public interface CommandRegistration {
Builder interactionMode(InteractionMode mode);
/**
* Define a simple help text for a command.
* Define a description text for a command.
*
* @param help the help text
* @param help the description text
* @return builder for chaining
*/
Builder help(String help);
Builder description(String description);
/**
* Define an {@link Availability} suppliear for a command.
@@ -623,19 +616,17 @@ public interface CommandRegistration {
private String command;
private InteractionMode interactionMode;
private String help;
private String group;
private String description;
private Supplier<Availability> availability;
private List<DefaultOptionSpec> optionSpecs;
private DefaultTargetSpec targetSpec;
public DefaultCommandRegistration(String[] commands, InteractionMode interactionMode, String help,
String group, String description, Supplier<Availability> availability,
List<DefaultOptionSpec> optionSpecs, DefaultTargetSpec targetSpec) {
public DefaultCommandRegistration(String[] commands, InteractionMode interactionMode, String group,
String description, Supplier<Availability> availability, List<DefaultOptionSpec> optionSpecs,
DefaultTargetSpec targetSpec) {
this.command = commandArrayToName(commands);
this.interactionMode = interactionMode;
this.help = help;
this.group = group;
this.description = description;
this.availability = availability;
@@ -653,11 +644,6 @@ public interface CommandRegistration {
return interactionMode;
}
@Override
public String getHelp() {
return help;
}
@Override
public String getGroup() {
return group;
@@ -712,7 +698,6 @@ public interface CommandRegistration {
private String[] commands;
private InteractionMode interactionMode = InteractionMode.ALL;
private String help;
private String group;
private String description;
private Supplier<Availability> availability;
@@ -738,8 +723,8 @@ public interface CommandRegistration {
}
@Override
public Builder help(String help) {
this.help = help;
public Builder description(String description) {
this.description = description;
return this;
}
@@ -774,7 +759,7 @@ public interface CommandRegistration {
Assert.notNull(commands, "command cannot be empty");
Assert.notNull(targetSpec, "target cannot be empty");
Assert.state(!(targetSpec.bean != null && targetSpec.function != null), "only one target can exist");
return new DefaultCommandRegistration(commands, interactionMode, help, group, description, availability,
return new DefaultCommandRegistration(commands, interactionMode, group, description, availability,
optionSpecs, targetSpec);
}
}

View File

@@ -49,7 +49,7 @@ public class CommandExecutionTests extends AbstractCommandTests {
public void testFunctionExecution() {
CommandRegistration r1 = CommandRegistration.builder()
.command("command1")
.help("help")
.description("help")
.withOption()
.longNames("arg1")
.description("some arg1")
@@ -66,7 +66,7 @@ public class CommandExecutionTests extends AbstractCommandTests {
public void testMethodExecution1() {
CommandRegistration r1 = CommandRegistration.builder()
.command("command1")
.help("help")
.description("help")
.withOption()
.longNames("arg1")
.description("some arg1")
@@ -84,7 +84,7 @@ public class CommandExecutionTests extends AbstractCommandTests {
public void testMethodExecution2() {
CommandRegistration r1 = CommandRegistration.builder()
.command("command1")
.help("help")
.description("help")
.withOption()
.longNames("arg1")
.description("some arg1")
@@ -102,7 +102,7 @@ public class CommandExecutionTests extends AbstractCommandTests {
public void testMethodSinglePositionalArgs() {
CommandRegistration r1 = CommandRegistration.builder()
.command("command1")
.help("help")
.description("help")
.withOption()
.longNames("arg1")
.description("some arg1")
@@ -122,7 +122,7 @@ public class CommandExecutionTests extends AbstractCommandTests {
public void testMethodSingleWithNamedArgs() {
CommandRegistration r1 = CommandRegistration.builder()
.command("command1")
.help("help")
.description("help")
.withOption()
.longNames("arg1")
.and()
@@ -140,7 +140,7 @@ public class CommandExecutionTests extends AbstractCommandTests {
public void testMethodMultiPositionalArgs() {
CommandRegistration r1 = CommandRegistration.builder()
.command("command1")
.help("help")
.description("help")
.withOption()
.longNames("arg1")
.description("some arg1")
@@ -160,7 +160,7 @@ public class CommandExecutionTests extends AbstractCommandTests {
public void testMethodMultiPositionalArgsAll() {
CommandRegistration r1 = CommandRegistration.builder()
.command("command1")
.help("help")
.description("help")
.withOption()
.longNames("arg1")
.description("some arg1")
@@ -180,7 +180,7 @@ public class CommandExecutionTests extends AbstractCommandTests {
public void testMethodMultipleArgs() {
CommandRegistration r1 = CommandRegistration.builder()
.command("command1")
.help("help")
.description("help")
.withOption()
.longNames("arg1")
.description("some arg1")
@@ -210,7 +210,7 @@ public class CommandExecutionTests extends AbstractCommandTests {
public void testMethodMultipleIntArgs() {
CommandRegistration r1 = CommandRegistration.builder()
.command("command1")
.help("help")
.description("help")
.withOption()
.longNames("arg1")
.description("some arg1")
@@ -239,7 +239,7 @@ public class CommandExecutionTests extends AbstractCommandTests {
public void testMethodMultiplePositionalStringArgs() {
CommandRegistration r1 = CommandRegistration.builder()
.command("command1")
.help("help")
.description("help")
.withOption()
.longNames("arg1")
.description("some arg1")
@@ -279,7 +279,7 @@ public class CommandExecutionTests extends AbstractCommandTests {
public void testMethodMultiplePositionalStringArgsMixed(String arg) {
CommandRegistration r1 = CommandRegistration.builder()
.command("command1")
.help("help")
.description("help")
.withOption()
.longNames("arg1")
.description("some arg1")
@@ -315,7 +315,7 @@ public class CommandExecutionTests extends AbstractCommandTests {
public void testShortCombinedWithoutValue() {
CommandRegistration r1 = CommandRegistration.builder()
.command("command1")
.help("help")
.description("help")
.withOption()
.shortNames('a')
.description("short arg a")
@@ -345,7 +345,7 @@ public class CommandExecutionTests extends AbstractCommandTests {
public void testShortCombinedSomeHavingValue() {
CommandRegistration r1 = CommandRegistration.builder()
.command("command1")
.help("help")
.description("help")
.withOption()
.shortNames('a')
.description("short arg a")
@@ -375,7 +375,7 @@ public class CommandExecutionTests extends AbstractCommandTests {
public void testFloatArrayOne() {
CommandRegistration r1 = CommandRegistration.builder()
.command("command1")
.help("help")
.description("help")
.withOption()
.longNames("arg1")
.type(float[].class)
@@ -393,7 +393,7 @@ public class CommandExecutionTests extends AbstractCommandTests {
public void testFloatArrayTwo() {
CommandRegistration r1 = CommandRegistration.builder()
.command("command1")
.help("help")
.description("help")
.withOption()
.longNames("arg1")
.type(float[].class)

View File

@@ -153,7 +153,7 @@ public class CommandRegistrationTests extends AbstractCommandTests {
public void testSimpleFullRegistrationWithFunction() {
CommandRegistration registration = CommandRegistration.builder()
.command("command1")
.help("help")
.description("help")
.withOption()
.longNames("arg1")
.description("some arg1")
@@ -163,7 +163,7 @@ public class CommandRegistrationTests extends AbstractCommandTests {
.and()
.build();
assertThat(registration.getCommand()).isEqualTo("command1");
assertThat(registration.getHelp()).isEqualTo("help");
assertThat(registration.getDescription()).isEqualTo("help");
assertThat(registration.getOptions()).hasSize(1);
assertThat(registration.getOptions().get(0).getLongNames()).containsExactly("arg1");
}
@@ -172,7 +172,7 @@ public class CommandRegistrationTests extends AbstractCommandTests {
public void testSimpleFullRegistrationWithMethod() {
CommandRegistration registration = CommandRegistration.builder()
.command("command1")
.help("help")
.description("help")
.withOption()
.longNames("arg1")
.description("some arg1")
@@ -182,7 +182,7 @@ public class CommandRegistrationTests extends AbstractCommandTests {
.and()
.build();
assertThat(registration.getCommand()).isEqualTo("command1");
assertThat(registration.getHelp()).isEqualTo("help");
assertThat(registration.getDescription()).isEqualTo("help");
assertThat(registration.getOptions()).hasSize(1);
}
@@ -190,7 +190,7 @@ public class CommandRegistrationTests extends AbstractCommandTests {
public void testOptionWithType() {
CommandRegistration registration = CommandRegistration.builder()
.command("command1")
.help("help")
.description("help")
.withOption()
.shortNames('v')
.type(boolean.class)
@@ -201,7 +201,7 @@ public class CommandRegistrationTests extends AbstractCommandTests {
.and()
.build();
assertThat(registration.getCommand()).isEqualTo("command1");
assertThat(registration.getHelp()).isEqualTo("help");
assertThat(registration.getDescription()).isEqualTo("help");
assertThat(registration.getOptions()).hasSize(1);
assertThat(registration.getOptions().get(0).getShortNames()).containsExactly('v');
assertThat(registration.getOptions().get(0).getType()).isEqualTo(ResolvableType.forType(boolean.class));
@@ -211,7 +211,7 @@ public class CommandRegistrationTests extends AbstractCommandTests {
public void testOptionWithRequired() {
CommandRegistration registration = CommandRegistration.builder()
.command("command1")
.help("help")
.description("help")
.withOption()
.shortNames('v')
.type(boolean.class)
@@ -223,14 +223,14 @@ public class CommandRegistrationTests extends AbstractCommandTests {
.and()
.build();
assertThat(registration.getCommand()).isEqualTo("command1");
assertThat(registration.getHelp()).isEqualTo("help");
assertThat(registration.getDescription()).isEqualTo("help");
assertThat(registration.getOptions()).hasSize(1);
assertThat(registration.getOptions().get(0).getShortNames()).containsExactly('v');
assertThat(registration.getOptions().get(0).isRequired()).isTrue();
registration = CommandRegistration.builder()
.command("command1")
.help("help")
.description("help")
.withOption()
.shortNames('v')
.type(boolean.class)
@@ -247,7 +247,7 @@ public class CommandRegistrationTests extends AbstractCommandTests {
registration = CommandRegistration.builder()
.command("command1")
.help("help")
.description("help")
.withOption()
.shortNames('v')
.type(boolean.class)
@@ -263,7 +263,7 @@ public class CommandRegistrationTests extends AbstractCommandTests {
registration = CommandRegistration.builder()
.command("command1")
.help("help")
.description("help")
.withOption()
.shortNames('v')
.type(boolean.class)
@@ -283,7 +283,7 @@ public class CommandRegistrationTests extends AbstractCommandTests {
public void testOptionWithDefaultValue() {
CommandRegistration registration = CommandRegistration.builder()
.command("command1")
.help("help")
.description("help")
.withOption()
.shortNames('v')
.type(boolean.class)
@@ -295,7 +295,7 @@ public class CommandRegistrationTests extends AbstractCommandTests {
.and()
.build();
assertThat(registration.getCommand()).isEqualTo("command1");
assertThat(registration.getHelp()).isEqualTo("help");
assertThat(registration.getDescription()).isEqualTo("help");
assertThat(registration.getOptions()).hasSize(1);
assertThat(registration.getOptions().get(0).getDefaultValue()).isEqualTo("defaultValue");
}