2
0
Fork 0
mirror of https://github.com/ethauvin/bld.git synced 2025-04-26 08:37:11 -07:00

Tweaks to help output and bld output when no commands are provided

This commit is contained in:
Geert Bevin 2024-07-17 22:56:07 -04:00
parent b0a75b22b7
commit 604f5ba424
3 changed files with 69 additions and 30 deletions

Binary file not shown.

View file

@ -227,12 +227,15 @@ public class BuildExecutor {
var show_help = false; var show_help = false;
show_help |= arguments_.removeAll(List.of(ARG_HELP1, ARG_HELP2, ARG_HELP3)); show_help |= arguments_.removeAll(List.of(ARG_HELP1, ARG_HELP2, ARG_HELP3));
showStacktrace = arguments_.removeAll(List.of(ARG_STACKTRACE1, ARG_STACKTRACE2)); showStacktrace = arguments_.removeAll(List.of(ARG_STACKTRACE1, ARG_STACKTRACE2));
show_help |= arguments_.isEmpty();
if (show_help) { if (show_help) {
new HelpOperation(this, Collections.emptyList()).execute(); new HelpOperation(this, Collections.emptyList()).execute();
return exitStatus_; return exitStatus_;
} }
else if (arguments_.isEmpty()) {
showBldHelp();
return exitStatus_;
}
while (!arguments_.isEmpty()) { while (!arguments_.isEmpty()) {
var command = arguments_.remove(0); var command = arguments_.remove(0);
@ -480,8 +483,7 @@ public class BuildExecutor {
} }
} else { } else {
var message = "Unknown command '" + command + "'"; var message = "Unknown command '" + command + "'";
new HelpOperation(this, arguments()).executePrintOverviewHelp(); showBldHelp();
System.err.println();
System.err.println("ERROR: " + message); System.err.println("ERROR: " + message);
exitStatus(ExitStatusException.EXIT_FAILURE); exitStatus(ExitStatusException.EXIT_FAILURE);
return false; return false;
@ -489,6 +491,16 @@ public class BuildExecutor {
return true; 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. * Retrieves the name of the currently executing command.
* *

View file

@ -60,8 +60,7 @@ public class HelpOperation {
} }
if (!outputJson_) { if (!outputJson_) {
System.err.println("Welcome to bld " + BldVersion.getVersion() + "."); executePrintWelcome();
System.err.println();
} }
var print_full_help = true; var print_full_help = true;
@ -93,19 +92,7 @@ public class HelpOperation {
} }
} }
/**
* 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) { private void executePrintOverviewHelp(Exception exception) {
var commands = executor_.buildCommands();
if (outputJson_) { if (outputJson_) {
var t = TemplateFactory.JSON.get("bld.help_commands"); var t = TemplateFactory.JSON.get("bld.help_commands");
@ -113,6 +100,7 @@ public class HelpOperation {
t.setValueEncoded("error-message", ExceptionUtils.getExceptionStackTrace(exception)); t.setValueEncoded("error-message", ExceptionUtils.getExceptionStackTrace(exception));
} }
var commands = executor_.buildCommands();
for (var command : commands.entrySet()) { for (var command : commands.entrySet()) {
if (t.isValueSet("commands")) { if (t.isValueSet("commands")) {
t.setValue("separator", ", "); t.setValue("separator", ", ");
@ -139,11 +127,35 @@ public class HelpOperation {
the other commands. the other commands.
Usage: help [command] [""" + JSON_ARGUMENT + "]"); Usage: help [command] [""" + JSON_ARGUMENT + "]");
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(""" System.err.println("""
The following commands are supported: The following commands are supported:
"""); """);
var commands = executor_.buildCommands();
var command_length = commands.keySet().stream().max(comparingInt(String::length)).get().length() + 2; var command_length = commands.keySet().stream().max(comparingInt(String::length)).get().length() + 2;
for (var command : commands.entrySet()) { for (var command : commands.entrySet()) {
System.err.print(" "); System.err.print(" ");
@ -152,20 +164,35 @@ public class HelpOperation {
System.err.print(build_help.getSummary()); 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(""" System.err.println("""
The following help arguments are supported: 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: The following bld arguments are supported:
--offline Work without internet (only as first argument) --offline Work without internet (only as first argument)
-?, -h, --help Shows this help message -?, -h, --help Shows the help
-D<name>=<value> Set a JVM system property -D<name>=<value> Set a JVM system property
-s, --stacktrace Print out the stacktrace for exceptions -s, --stacktrace Print out the stacktrace for exceptions
"""); """);
} }
}
} }