From 934a99fa014c1f8380fef2e72d7fbd02f667a1c9 Mon Sep 17 00:00:00 2001 From: Romain Manni-Bucau Date: Fri, 5 Mar 2021 11:44:15 +0100 Subject: [PATCH] enable to hide args in help command --- .../bundlebee/core/command/impl/HelpCommand.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/bundlebee-core/src/main/java/io/yupiik/bundlebee/core/command/impl/HelpCommand.java b/bundlebee-core/src/main/java/io/yupiik/bundlebee/core/command/impl/HelpCommand.java index af0bd9df..c8b1d977 100644 --- a/bundlebee-core/src/main/java/io/yupiik/bundlebee/core/command/impl/HelpCommand.java +++ b/bundlebee-core/src/main/java/io/yupiik/bundlebee/core/command/impl/HelpCommand.java @@ -52,6 +52,11 @@ public class HelpCommand implements Executable { @ConfigProperty(name = "bundlebee.help.command", defaultValue = UNSET) private String command; + @Inject + @Description("If `false` args are not shown, enable a lighter output.") + @ConfigProperty(name = "bundlebee.help.args", defaultValue = "true") + private boolean showArgs; + @Override public String name() { return "help"; @@ -76,20 +81,20 @@ public CompletionStage execute() { final var description = executable.description(); final int end = description.indexOf("\n//"); final var desc = reflowText(end > 0 ? description.substring(0, end) : description, " ") + - (parameters.isEmpty() ? "" : "\n"); + (!showArgs || parameters.isEmpty() ? "" : "\n"); return "" + " [] " + executable.name() + ": " + - Character.toLowerCase(desc.charAt(0)) + desc.substring(1) + "\n" + + Character.toLowerCase(desc.charAt(0)) + desc.substring(1) + (showArgs ? "\n" + parameters.stream().map(p -> "" + " " + p.getName() + (p.getDefaultValue() != null ? " (default: " + p.getDefaultValue() .replace("\n", "\\\\n") + ")" : "") + ": " + reflowText(p.getDescription(), " ")) .sorted() - .collect(joining("\n")); + .collect(joining("\n")) : ""); }) .sorted() - .collect(joining("\n\n", "", "\n"))); + .collect(joining(showArgs ? "\n\n" : "\n", "", "\n"))); return completedFuture(null); }