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");
}

View File

@@ -26,7 +26,7 @@ public class FunctionCommands {
public CommandRegistration commandRegistration1() {
return CommandRegistration.builder()
.command("function", "command1")
.help("function sample")
.description("function sample")
.group("Function Commands")
.withTarget()
.function(ctx -> {
@@ -44,7 +44,7 @@ public class FunctionCommands {
public CommandRegistration commandRegistration2() {
return CommandRegistration.builder()
.command("function", "command2")
.help("function sample")
.description("function sample")
.group("Function Commands")
.withTarget()
.function(ctx -> {
@@ -73,7 +73,7 @@ public class FunctionCommands {
public CommandRegistration commandRegistration3() {
return CommandRegistration.builder()
.command("function", "command3")
.help("function sample")
.description("function sample")
.group("Function Commands")
.withTarget()
.consumer(ctx -> {
@@ -92,7 +92,7 @@ public class FunctionCommands {
public CommandRegistration commandRegistration4() {
return CommandRegistration.builder()
.command("function", "command4")
.help("function sample")
.description("function sample")
.group("Function Commands")
.withTarget()
.consumer(ctx -> {

View File

@@ -37,14 +37,14 @@ public class RegisterCommands extends AbstractShellComponent {
registered1 = CommandRegistration.builder()
.command("register registered1")
.group(GROUP)
.help("registered1 command")
.description("registered1 command")
.withTarget()
.method(pojoMethods, "registered1")
.and()
.build();
registered2 = CommandRegistration.builder()
.command("register registered2")
.help("registered2 command")
.description("registered2 command")
.group(GROUP)
.withTarget()
.method(pojoMethods, "registered2")
@@ -55,7 +55,7 @@ public class RegisterCommands extends AbstractShellComponent {
.build();
registered3 = CommandRegistration.builder()
.command("register registered3")
.help("registered3 command")
.description("registered3 command")
.group(GROUP)
.withTarget()
.method(pojoMethods, "registered3")
@@ -84,7 +84,7 @@ public class RegisterCommands extends AbstractShellComponent {
};
CommandRegistration registration = CommandRegistration.builder()
.command(command)
.help("registered4 command")
.description("registered4 command")
.group(GROUP)
.withTarget()
.function(function)

View File

@@ -90,7 +90,7 @@ public class ResolvedCommands {
CommandRegistration resolved1 = CommandRegistration.builder()
.command("resolve server1 command1")
.group(GROUP)
.help("server1 command1")
.description("server1 command1")
.withTarget()
.function(ctx -> {
return "hi from server1 command1";
@@ -115,7 +115,7 @@ public class ResolvedCommands {
CommandRegistration resolved1 = CommandRegistration.builder()
.command("resolve server2 command1")
.group(GROUP)
.help("server2 command1")
.description("server2 command1")
.withTarget()
.function(ctx -> {
return "hi from server2 command1";
@@ -125,7 +125,7 @@ public class ResolvedCommands {
CommandRegistration resolved2 = CommandRegistration.builder()
.command("resolve server2 command2")
.group(GROUP)
.help("server2 command2")
.description("server2 command2")
.withTarget()
.function(ctx -> {
return "hi from server2 command2";

View File

@@ -127,7 +127,7 @@ public class Help extends AbstractShellComponent {
List<ParameterDescription> parameterDescriptions = getParameterDescriptions(registration);
// NAME
documentCommandName(result, command, registration.getHelp());
documentCommandName(result, command, registration.getDescription());
// SYNOPSYS
documentSynopsys(result, command, parameterDescriptions);
@@ -300,7 +300,7 @@ public class Help extends AbstractShellComponent {
.append(prefix)
.append(String.join(", ", e.getValue()), AttributedStyle.BOLD)
.append(": ")
.append(e.getKey().getHelp())
.append(e.getKey().getDescription())
.append('\n');
});
if (showGroups) {

View File

@@ -91,7 +91,7 @@ public class HelpTests {
public void testCommandHelp() throws Exception {
CommandRegistration registration = CommandRegistration.builder()
.command("first-command")
.help("A rather extensive description of some command.")
.description("A rather extensive description of some command.")
.withTarget()
.method(commandsPojo, "firstCommand")
.and()
@@ -127,7 +127,7 @@ public class HelpTests {
public void testCommandList() throws Exception {
CommandRegistration registration1 = CommandRegistration.builder()
.command("first-command")
.help("A rather extensive description of some command.")
.description("A rather extensive description of some command.")
.withTarget()
.method(commandsPojo, "firstCommand")
.and()
@@ -140,7 +140,7 @@ public class HelpTests {
CommandRegistration registration2 = CommandRegistration.builder()
.command("second-command")
.help("The second command. This one is known under several aliases as well.")
.description("The second command. This one is known under several aliases as well.")
.withTarget()
.method(commandsPojo, "secondCommand")
.and()
@@ -150,7 +150,7 @@ public class HelpTests {
CommandRegistration registration3 = CommandRegistration.builder()
.command("second-command")
.help("The last command.")
.description("The last command.")
.withTarget()
.method(commandsPojo, "thirdCommand")
.and()
@@ -159,7 +159,7 @@ public class HelpTests {
CommandRegistration registration4 = CommandRegistration.builder()
.command("first-group-command")
.help("The first command in a separate group.")
.description("The first command in a separate group.")
.group("Example Group")
.withTarget()
.method(commandsPojo, "firstCommandInGroup")
@@ -169,7 +169,7 @@ public class HelpTests {
CommandRegistration registration5 = CommandRegistration.builder()
.command("second-group-command")
.help("The second command in a separate group.")
.description("The second command in a separate group.")
.group("Example Group")
.withTarget()
.method(commandsPojo, "secondCommandInGroup")

View File

@@ -86,7 +86,7 @@ public class StandardMethodTargetRegistrar implements MethodTargetRegistrar, App
Builder builder = CommandRegistration.builder()
.command(key)
.group(group)
.help(shellMapping.value())
.description(shellMapping.value())
.interactionMode(shellMapping.interactionMode())
.availability(availabilityIndicator);