Skip to content

Commit

Permalink
Tweaks to help output and bld output when no commands are provided
Browse files Browse the repository at this point in the history
  • Loading branch information
gbevin committed Jul 18, 2024
1 parent b0a75b2 commit 604f5ba
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 30 deletions.
Binary file modified lib/bld/bld-wrapper.jar
Binary file not shown.
18 changes: 15 additions & 3 deletions src/main/java/rife/bld/BuildExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -480,15 +483,24 @@ 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;
}
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.
*
Expand Down
81 changes: 54 additions & 27 deletions src/main/java/rife/bld/operations/HelpOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -93,26 +92,15 @@ 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");

if (exception != null) {
t.setValueEncoded("error-message", ExceptionUtils.getExceptionStackTrace(exception));
}

var commands = executor_.buildCommands();
for (var command : commands.entrySet()) {
if (t.isValueSet("commands")) {
t.setValue("separator", ", ");
Expand All @@ -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<name>=<value> Set a JVM system property
-s, --stacktrace Print out the stacktrace for exceptions
""");
}
}
}

0 comments on commit 604f5ba

Please sign in to comment.