2
0
Fork 0
mirror of https://github.com/ethauvin/bld.git synced 2025-04-25 16:27: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;
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 class BuildExecutor {
}
} 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 class BuildExecutor {
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.
*

View file

@ -60,8 +60,7 @@ public class HelpOperation {
}
if (!outputJson_) {
System.err.println("Welcome to bld " + BldVersion.getVersion() + ".");
System.err.println();
executePrintWelcome();
}
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) {
var commands = executor_.buildCommands();
if (outputJson_) {
var t = TemplateFactory.JSON.get("bld.help_commands");
@ -113,6 +100,7 @@ public class HelpOperation {
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 @@ public class HelpOperation {
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<name>=<value> Set a JVM system property
-s, --stacktrace Print out the stacktrace for exceptions
""");
}
}
}