From 604f5ba424cf4d4bfb17f71c6651224a4d041a45 Mon Sep 17 00:00:00 2001 From: Geert Bevin Date: Wed, 17 Jul 2024 22:56:07 -0400 Subject: [PATCH] Tweaks to help output and bld output when no commands are provided --- lib/bld/bld-wrapper.jar | Bin 29818 -> 29818 bytes src/main/java/rife/bld/BuildExecutor.java | 18 +++- .../rife/bld/operations/HelpOperation.java | 81 ++++++++++++------ 3 files changed, 69 insertions(+), 30 deletions(-) diff --git a/lib/bld/bld-wrapper.jar b/lib/bld/bld-wrapper.jar index 8c431c8345cfec2ff7214c9458aaea296e64ad19..66dad4b5e201406bc6701a0a29ca9b87f9152a8f 100644 GIT binary patch delta 140 zcmezMg7Mc2MxFp~W)=|!4h{~6Z`&sF)H8kCwz2oLC6L-2Wp#`RNKcNk(wZz^EVwz= zHW0+$yutprE{I;6dw~%|*XJ97)om{H1S$Vl=mMf#io8J7grZOo^&CRk6}y3WZN>3m M!QucAWm)0~02^pQhX4Qo delta 140 zcmezMg7Mc2MxFp~W)=|!4h{~6lba{<)H9vjys`JRC6L-2Wp#`RNKcNk(wZz^EVwz= zHW0+$yutprE{I;6dw~%|*XJ97)om{H1S$Vl=mMf#io8J7grZOo^&CRk6}y3WZN>3m M!QucAWm)0~0AYzfhX4Qo diff --git a/src/main/java/rife/bld/BuildExecutor.java b/src/main/java/rife/bld/BuildExecutor.java index 5f7c70d..cda33b1 100644 --- a/src/main/java/rife/bld/BuildExecutor.java +++ b/src/main/java/rife/bld/BuildExecutor.java @@ -227,12 +227,15 @@ public int execute(String[] arguments) { var show_help = false; show_help |= arguments_.removeAll(List.of(ARG_HELP1, ARG_HELP2, ARG_HELP3)); showStacktrace = arguments_.removeAll(List.of(ARG_STACKTRACE1, ARG_STACKTRACE2)); - show_help |= arguments_.isEmpty(); if (show_help) { new HelpOperation(this, Collections.emptyList()).execute(); return exitStatus_; } + else if (arguments_.isEmpty()) { + showBldHelp(); + return exitStatus_; + } while (!arguments_.isEmpty()) { var command = arguments_.remove(0); @@ -480,8 +483,7 @@ public boolean executeCommand(String command) } } else { var message = "Unknown command '" + command + "'"; - new HelpOperation(this, arguments()).executePrintOverviewHelp(); - System.err.println(); + showBldHelp(); System.err.println("ERROR: " + message); exitStatus(ExitStatusException.EXIT_FAILURE); return false; @@ -489,6 +491,16 @@ public boolean executeCommand(String command) return true; } + private void showBldHelp() { + var help = new HelpOperation(this, arguments()); + help.executePrintWelcome(); + System.err.println(""" + The bld CLI provides its features through a series of commands that + perform specific tasks."""); + help.executePrintCommands(); + help.executePrintBldArguments(); + } + /** * Retrieves the name of the currently executing command. * diff --git a/src/main/java/rife/bld/operations/HelpOperation.java b/src/main/java/rife/bld/operations/HelpOperation.java index aae5c68..d460164 100644 --- a/src/main/java/rife/bld/operations/HelpOperation.java +++ b/src/main/java/rife/bld/operations/HelpOperation.java @@ -60,8 +60,7 @@ public void execute() { } if (!outputJson_) { - System.err.println("Welcome to bld " + BldVersion.getVersion() + "."); - System.err.println(); + executePrintWelcome(); } var print_full_help = true; @@ -93,19 +92,7 @@ public void execute() { } } - /** - * Part of the {@link #execute} operation, prints the help overview - * with summaries of all build commands. - * - * @since 1.5 - */ - public void executePrintOverviewHelp() { - executePrintOverviewHelp(null); - } - private void executePrintOverviewHelp(Exception exception) { - var commands = executor_.buildCommands(); - if (outputJson_) { var t = TemplateFactory.JSON.get("bld.help_commands"); @@ -113,6 +100,7 @@ private void executePrintOverviewHelp(Exception exception) { t.setValueEncoded("error-message", ExceptionUtils.getExceptionStackTrace(exception)); } + var commands = executor_.buildCommands(); for (var command : commands.entrySet()) { if (t.isValueSet("commands")) { t.setValue("separator", ", "); @@ -139,33 +127,72 @@ private void executePrintOverviewHelp(Exception exception) { the other commands. Usage: help [command] [""" + JSON_ARGUMENT + "]"); - System.err.println(""" + + executePrintCommands(); + executePrintHelpArguments(); + executePrintBldArguments(); + } + } + + /** + * Part of the {@link #execute} operation, prints the welcome message. + * + * @since 2.0 + */ + public void executePrintWelcome() { + System.err.println("Welcome to bld " + BldVersion.getVersion() + "."); + System.err.println(); + } + + /** + * Part of the {@link #execute} operation, prints the summaries of all supported build commands. + * + * @since 2.0 + */ + public void executePrintCommands() { + System.err.println(""" The following commands are supported: """); - var command_length = commands.keySet().stream().max(comparingInt(String::length)).get().length() + 2; - for (var command : commands.entrySet()) { - System.err.print(" "); - System.err.printf("%-" + command_length + "s", command.getKey()); - var build_help = command.getValue().getHelp(); - System.err.print(build_help.getSummary()); - System.err.println(); - } + var commands = executor_.buildCommands(); + var command_length = commands.keySet().stream().max(comparingInt(String::length)).get().length() + 2; + for (var command : commands.entrySet()) { + System.err.print(" "); + System.err.printf("%-" + command_length + "s", command.getKey()); + var build_help = command.getValue().getHelp(); + System.err.print(build_help.getSummary()); + System.err.println(); + } + } - System.err.println(""" + /** + * Part of the {@link #execute} operation, prints the supported help arguments. + * + * @since 2.0 + */ + public void executePrintHelpArguments() { + System.err.println(""" The following help arguments are supported: - --json Output help in JSON format + --json Output help in JSON format"""); + } + + /** + * Part of the {@link #execute} operation, prints the supported bld arguments. + * + * @since 2.0 + */ + public void executePrintBldArguments() { + System.err.println(""" The following bld arguments are supported: --offline Work without internet (only as first argument) - -?, -h, --help Shows this help message + -?, -h, --help Shows the help -D= Set a JVM system property -s, --stacktrace Print out the stacktrace for exceptions """); - } } } \ No newline at end of file