From c521d75ef7051cf18e4c7756af112278938a5dad Mon Sep 17 00:00:00 2001 From: zzz Date: Wed, 21 Dec 2022 09:42:57 -0500 Subject: [PATCH] CLI: List available commands more compactly --- core/java/src/net/i2p/util/CommandLine.java | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/core/java/src/net/i2p/util/CommandLine.java b/core/java/src/net/i2p/util/CommandLine.java index 0b22ba86d..fa948f69c 100644 --- a/core/java/src/net/i2p/util/CommandLine.java +++ b/core/java/src/net/i2p/util/CommandLine.java @@ -111,14 +111,33 @@ public class CommandLine { protected static void printCommands(List classes) { System.err.println("Available commands:"); List cmds = new ArrayList(classes.size()); + int max = 0; for (String cls : classes) { String ccmd = cls.substring(cls.lastIndexOf('.') + 1).toLowerCase(Locale.US); cmds.add(ccmd); + if (ccmd.length() > max) + max = ccmd.length(); } Collections.sort(cmds); + StringBuilder buf = new StringBuilder(80); for (String cmd : cmds) { - System.err.println(" " + cmd); + int len = buf.length(); + if (len == 0) + buf.append(" "); + buf.append(cmd); + if (len > 80 - max) { + System.err.println(buf); + buf.setLength(0); + } else { + int spc = 1 + max - cmd.length(); + for (int i = 0; i < spc; i++) { + buf.append(' '); + } + } } + if (buf.length() > 0) + System.out.println(buf); + System.err.println(); System.err.println("Enter \"help command\" for detailed help."); } }