From 7b74b35794a0f93438c56ce9c7f6b75a0ffe3cfa Mon Sep 17 00:00:00 2001 From: SerLiunx-ctrl <17689543@qq.com> Date: Wed, 5 Feb 2025 09:21:44 +0800 Subject: [PATCH] =?UTF-8?q?change:=20=E8=B0=83=E6=95=B4help=E6=8C=87?= =?UTF-8?q?=E4=BB=A4=E6=A0=B7=E5=BC=8F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../support/command/target/HelpCommand.java | 58 +++++++++++++------ 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/serliunx/ddns/support/command/target/HelpCommand.java b/src/main/java/com/serliunx/ddns/support/command/target/HelpCommand.java index 1287085..514239f 100644 --- a/src/main/java/com/serliunx/ddns/support/command/target/HelpCommand.java +++ b/src/main/java/com/serliunx/ddns/support/command/target/HelpCommand.java @@ -49,15 +49,7 @@ public class HelpCommand extends AbstractCommand { } System.out.println(); } else { - System.out.println(); - commands.forEach((k, v) -> { - // 忽略 help 自身 - if (k.equals(getName())) { - return; - } - coloredPrintf("&2%s&r\t - &6%s&r - &5%s%n", k, v.getDescription(), v.getUsage()); - }); - System.out.println(); + printCommandDetails(commands); coloredPrintf("&6&l使用 help <指令> 来查看更详细的帮助信息."); } return true; @@ -83,16 +75,15 @@ public class HelpCommand extends AbstractCommand { final String currentWord = line.word(); - if (index == 1) { - commands.keySet().forEach(k -> { - if (k.equals("help")) { - return; - } - if (k.startsWith(currentWord)) { - candidates.add(new Candidate(k)); - } - }); - } + if (index != 1) + return; + + commands.keySet().forEach(k -> { + if (k.startsWith(currentWord) && + !k.equals("help")) { + candidates.add(new Candidate(k)); + } + }); } /** @@ -101,4 +92,33 @@ public class HelpCommand extends AbstractCommand { private Map getAllCommands() { return CommandDispatcher.getInstance().getCommands(); } + + /** + * 输出指令详细信息, 包括子命令及参数信息. + * + * @param commands 指令集合 + */ + private void printCommandDetails(final Map commands) { + if (commands == null || commands.isEmpty()) + return; + System.out.println(); + System.out.println(); + commands.forEach((k, v) -> { + coloredPrintf("&2%s&r - &6%s&r", k, v.getDescription()); + coloredPrintf("\t&5用法:&r &3%s", v.getUsage()); + final List subCommands = v.getSubCommands(); + if (subCommands == null || subCommands.isEmpty()) { + coloredPrintf("\t&5参数:&r 无"); + } else { + coloredPrintf("\t&5参数:"); + subCommands.forEach(c -> { + coloredPrintf("\t&2%s&r - &6%s&r", c.getName(), c.getDescription()); + coloredPrintf("\t\t&5用法:&r &3%s", c.getUsage()); + }); + } + System.out.println(); + }); + System.out.println(); + System.out.println(); + } } \ No newline at end of file