change: 调整help指令样式.

This commit is contained in:
2025-02-05 09:21:44 +08:00
parent 2cd4eeabd2
commit 7b74b35794

View File

@@ -49,15 +49,7 @@ public class HelpCommand extends AbstractCommand {
} }
System.out.println(); System.out.println();
} else { } else {
System.out.println(); printCommandDetails(commands);
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();
coloredPrintf("&6&l使用 help <指令> 来查看更详细的帮助信息."); coloredPrintf("&6&l使用 help <指令> 来查看更详细的帮助信息.");
} }
return true; return true;
@@ -83,16 +75,15 @@ public class HelpCommand extends AbstractCommand {
final String currentWord = line.word(); final String currentWord = line.word();
if (index == 1) { if (index != 1)
commands.keySet().forEach(k -> { return;
if (k.equals("help")) {
return; commands.keySet().forEach(k -> {
} if (k.startsWith(currentWord) &&
if (k.startsWith(currentWord)) { !k.equals("help")) {
candidates.add(new Candidate(k)); candidates.add(new Candidate(k));
} }
}); });
}
} }
/** /**
@@ -101,4 +92,33 @@ public class HelpCommand extends AbstractCommand {
private Map<String, Command> getAllCommands() { private Map<String, Command> getAllCommands() {
return CommandDispatcher.getInstance().getCommands(); return CommandDispatcher.getInstance().getCommands();
} }
/**
* 输出指令详细信息, 包括子命令及参数信息.
*
* @param commands 指令集合
*/
private void printCommandDetails(final Map<String, Command> 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<Command> 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();
}
} }