diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/AbstractCommand.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/AbstractCommand.java index d220d834eb..6030c211da 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/AbstractCommand.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/AbstractCommand.java @@ -29,6 +29,8 @@ import org.springframework.boot.cli.command.options.OptionHelp; */ public abstract class AbstractCommand implements Command { + protected static final String NEW_LINE = System.getProperty("line.separator"); + private final String name; private final String description; @@ -58,6 +60,11 @@ public abstract class AbstractCommand implements Command { return null; } + @Override + public String getExamples() { + return null; + } + @Override public String getHelp() { return null; diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/Command.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/Command.java index 05d6a3c21b..97ee5f33a8 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/Command.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/Command.java @@ -26,6 +26,7 @@ import org.springframework.boot.cli.command.status.ExitStatus; * * @author Phillip Webb * @author Dave Syer + * @author Stephane Nicoll * @see #run(String...) */ public interface Command { @@ -47,6 +48,13 @@ public interface Command { */ String getUsageHelp(); + /** + * Return some examples for the command. This can be a multi-lined string with + * one example per line, starting with the description and ending with the + * example. + */ + String getExamples(); + /** * Gets full help text for the command, e.g. a longer description and one line per * option. diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/core/HelpCommand.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/core/HelpCommand.java index 90f8f4b0c5..fc4627f101 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/core/HelpCommand.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/core/HelpCommand.java @@ -101,6 +101,12 @@ public class HelpCommand extends AbstractCommand { + " " + command.getUsageHelp()); Log.info(""); } + if (command.getExamples() != null) { + Log.info("example(s):"); + Log.info(""); + Log.info(command.getExamples()); + Log.info(""); + } if (command.getHelp() != null) { Log.info(command.getHelp()); } diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitCommand.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitCommand.java index 4f4ca9e175..650fa4779d 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitCommand.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitCommand.java @@ -53,6 +53,16 @@ public class InitCommand extends OptionParsingCommand { return "[options] [location]"; } + @Override + public String getExamples() { + StringBuilder sb = new StringBuilder(); + sb.append("Lists the capabilities of the service: spring init --list").append(NEW_LINE); + sb.append("Creates a default project: spring init").append(NEW_LINE); + sb.append("Creates a web my-app.zip: spring init -d=web my-app.zip").append(NEW_LINE); + sb.append("Creates a web/data-jpa gradle project unpacked: spring init -d=web,jpa --build=gradle my-dir/"); + return sb.toString(); + } + static class InitOptionHandler extends OptionHandler { private final ServiceCapabilitiesReportGenerator serviceCapabilitiesReport;