diff --git a/LauncherCore/src/main/java/pro/gravit/utils/command/basic/HelpCommand.java b/LauncherCore/src/main/java/pro/gravit/utils/command/basic/HelpCommand.java
index 77c819d1..95f00723 100644
--- a/LauncherCore/src/main/java/pro/gravit/utils/command/basic/HelpCommand.java
+++ b/LauncherCore/src/main/java/pro/gravit/utils/command/basic/HelpCommand.java
@@ -1,5 +1,6 @@
package pro.gravit.utils.command.basic;
+import java.util.Arrays;
import java.util.Map.Entry;
import org.fusesource.jansi.Ansi;
@@ -13,7 +14,7 @@
public final class HelpCommand extends Command {
private CommandHandler handler;
- private static void printCommand(String name, Command command) {
+ public static void printCommand(String name, Command command) {
String args = command.getArgsDescription();
//LogHelper.subInfo("%s %s - %s", name, args == null ? "[nothing]" : args, command.getUsageDescription());
LogHelper.rawLog(() -> FormatHelper.rawFormat(LogHelper.Level.INFO, LogHelper.getDataTime(), true) + String.format("%s %s - %s", name, args == null ? "[nothing]" : args, command.getUsageDescription()), () -> {
@@ -31,6 +32,27 @@ private static void printCommand(String name, Command command) {
}, () -> LogHelper.htmlFormatLog(LogHelper.Level.INFO, LogHelper.getDataTime(), String.format("%s %s - %s", name, args == null ? "[nothing]" : args, command.getUsageDescription()), true));
}
+ public static void printSubCommandsHelp(String base, Command command)
+ {
+ command.childCommands.forEach((k, v) -> {
+ printCommand(base.concat(" ").concat(k), v);
+ });
+ }
+
+ public static void printSubCommandsHelp(String name, String[] args, Command command) throws CommandException
+ {
+ if(args.length == 0)
+ {
+ printSubCommandsHelp(name, command);
+ }
+ else
+ {
+ Command child = command.childCommands.get(args[0]);
+ if(child == null) throw new CommandException(String.format("Unknown sub command: '%s'", args[0]));
+ printSubCommandsHelp(name.concat(" ").concat(args[0]), Arrays.copyOfRange(args,1 , args.length), child);
+ }
+ }
+
private static void printCategory(String name, String description) {
if (description != null) LogHelper.info("Category: %s - %s", name, description);
else LogHelper.info("Category: %s", name);
@@ -58,7 +80,9 @@ public void invoke(String... args) throws CommandException {
}
// Print command help
- printCommand(args[0]);
+ if(args.length == 1)
+ printCommand(args[0]);
+ printSubCommandsHelp(args[0], Arrays.copyOfRange(args, 1 , args.length), handler.lookup(args[0]));
}
private void printCommand(String name) throws CommandException {