[FEATURE] Полностью распределены команды по категориям, команда help доступна из libLauncher

This commit is contained in:
Gravit 2019-04-13 06:43:20 +07:00
parent 1f716f0307
commit 7869618d51
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
2 changed files with 31 additions and 25 deletions

View file

@ -12,13 +12,14 @@
import ru.gravit.launchserver.command.modules.ModulesCommand;
import ru.gravit.launchserver.command.service.*;
import ru.gravit.utils.command.BaseCommandCategory;
import ru.gravit.utils.command.basic.HelpCommand;
public abstract class CommandHandler extends ru.gravit.utils.command.CommandHandler {
public static void registerCommands(ru.gravit.utils.command.CommandHandler handler) {
LaunchServer server = LaunchServer.server;
BaseCommandCategory basic = new BaseCommandCategory();
// Register basic commands
basic.registerCommand("help", new HelpCommand(server));
basic.registerCommand("help", new HelpCommand(server.commandHandler));
basic.registerCommand("version", new VersionCommand(server));
basic.registerCommand("build", new BuildCommand(server));
basic.registerCommand("stop", new StopCommand(server));
@ -61,22 +62,28 @@ public static void registerCommands(ru.gravit.utils.command.CommandHandler handl
handler.registerCategory(authCategory);
//Register dump commands
handler.registerCommand("dumpSessions", new DumpSessionsCommand(server));
handler.registerCommand("dumpEntryCache", new DumpEntryCacheCommand(server));
BaseCommandCategory dump = new BaseCommandCategory();
dump.registerCommand("dumpSessions", new DumpSessionsCommand(server));
dump.registerCommand("dumpEntryCache", new DumpEntryCacheCommand(server));
Category dumpCategory = new Category(dump,"dump", "Dump runtime data");
handler.registerCategory(dumpCategory);
//Register service commands
handler.registerCommand("reload", new ReloadCommand(server));
handler.registerCommand("reloadAll", new ReloadAllCommand(server));
handler.registerCommand("reloadList", new ReloadListCommand(server));
handler.registerCommand("config", new ConfigCommand(server));
handler.registerCommand("configHelp", new ConfigHelpCommand(server));
handler.registerCommand("configList", new ConfigListCommand(server));
handler.registerCommand("serverStatus", new ServerStatusCommand(server));
handler.registerCommand("checkInstall", new CheckInstallCommand(server));
handler.registerCommand("multi", new MultiCommand(server));
handler.registerCommand("getModulus", new GetModulusCommand(server));
handler.registerCommand("component", new ComponentCommand(server));
handler.registerCommand("givePermission", new GivePermissionsCommand(server));
handler.registerCommand("getPermissions", new GetPermissionsCommand(server));
BaseCommandCategory service = new BaseCommandCategory();
service.registerCommand("reload", new ReloadCommand(server));
service.registerCommand("reloadAll", new ReloadAllCommand(server));
service.registerCommand("reloadList", new ReloadListCommand(server));
service.registerCommand("config", new ConfigCommand(server));
service.registerCommand("configHelp", new ConfigHelpCommand(server));
service.registerCommand("configList", new ConfigListCommand(server));
service.registerCommand("serverStatus", new ServerStatusCommand(server));
service.registerCommand("checkInstall", new CheckInstallCommand(server));
service.registerCommand("multi", new MultiCommand(server));
service.registerCommand("getModulus", new GetModulusCommand(server));
service.registerCommand("component", new ComponentCommand(server));
service.registerCommand("givePermission", new GivePermissionsCommand(server));
service.registerCommand("getPermissions", new GetPermissionsCommand(server));
Category serviceCategory = new Category(service,"service", "Managing LaunchServer Components");
handler.registerCategory(serviceCategory);
}
}

View file

@ -1,9 +1,7 @@
package ru.gravit.launchserver.command.basic;
package ru.gravit.utils.command.basic;
import org.fusesource.jansi.Ansi;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.utils.command.Command;
import ru.gravit.utils.command.CommandCategory;
import ru.gravit.utils.command.CommandException;
import ru.gravit.utils.command.CommandHandler;
import ru.gravit.utils.helper.LogHelper;
@ -11,7 +9,8 @@
import java.util.Map;
import java.util.Map.Entry;
public final class HelpCommand extends ru.gravit.launchserver.command.Command {
public final class HelpCommand extends Command {
private CommandHandler handler;
private static void printCommand(String name, Command command) {
String args = command.getArgsDescription();
//LogHelper.subInfo("%s %s - %s", name, args == null ? "[nothing]" : args, command.getUsageDescription());
@ -36,8 +35,8 @@ private static void printCategory(String name, String description)
else LogHelper.info("Category: %s", name);
}
public HelpCommand(LaunchServer server) {
super(server);
public HelpCommand(CommandHandler handler) {
this.handler = handler;
}
@Override
@ -62,18 +61,18 @@ public void invoke(String... args) throws CommandException {
}
private void printCommand(String name) throws CommandException {
printCommand(name, server.commandHandler.lookup(name));
printCommand(name, handler.lookup(name));
}
private void printCommands() {
for(CommandHandler.Category category : server.commandHandler.getCategories())
for(CommandHandler.Category category : handler.getCategories())
{
printCategory(category.name, category.description);
for (Entry<String, Command> entry : category.category.commandsMap().entrySet())
printCommand(entry.getKey(), entry.getValue());
}
printCategory("Base", null);
for (Entry<String, Command> entry : server.commandHandler.getBaseCategory().commandsMap().entrySet())
for (Entry<String, Command> entry : handler.getBaseCategory().commandsMap().entrySet())
printCommand(entry.getKey(), entry.getValue());
}