use of de.jackwhite20.japs.server.command.Command in project JaPS by JackWhite20.
the class JaPS method start.
public void start() throws Exception {
logger.info("Starting JaPS server");
running = true;
jaPSServer = new JaPSServer(config);
String line;
while (running) {
line = consoleReader.readLine("> ");
if (!line.isEmpty()) {
String[] split = ARGS_SPLIT.split(line);
if (split.length == 0) {
continue;
}
String commandName = split[0].toLowerCase();
// Try to get the command with the name
Command command = commandManager.findCommand(commandName);
if (command != null) {
logger.log(Level.INFO, "Executing command: {0}", line);
String[] cmdArgs = Arrays.copyOfRange(split, 1, split.length);
command.execute(cmdArgs);
} else {
logger.log(Level.INFO, "Command not found!");
}
}
}
}
use of de.jackwhite20.japs.server.command.Command in project JaPS by JackWhite20.
the class JaPS method init.
public void init() {
System.setProperty("library.jansi.version", "JaPS");
AnsiConsole.systemInstall();
try {
consoleReader = new ConsoleReader();
consoleReader.setExpandEvents(false);
} catch (IOException e) {
e.printStackTrace();
}
// Setup logging system
logger = new JaPSLogger(consoleReader);
System.setErr(new PrintStream(new LoggingOutputStream(logger, Level.SEVERE), true));
System.setOut(new PrintStream(new LoggingOutputStream(logger, Level.INFO), true));
// Register command
commandManager = new CommandManager();
commandManager.addCommand(new HelpCommand("help", new String[] { "h" }, "Show this output"));
commandManager.addCommand(new SubCommand("sub", new String[] { "s", "subscribe" }, "Subscribe a channel and view it's prepareCacheSync passing"));
commandManager.addCommand(new UnsubCommand("unsub", new String[] {}, "Unsubscribe previous subscribed channels"));
commandManager.addCommand(new EndCommand("end", new String[] { "stop" }, "Shutdown the server"));
commandManager.addCommand(new SetCommand("set", new String[] { "add" }, "Sets a key and value"));
commandManager.addCommand(new GetCommand("get", new String[] {}, "Gets a value from a key"));
commandManager.addCommand(new DeleteCommand("delete", new String[] { "remove", "del", "rm" }, "Gets a value from a key"));
commandManager.addCommand(new SnapshotCommand("snapshot", new String[] {}, "Takes a memory snapshot"));
// Autocomplete commands
consoleReader.addCompleter(new StringsCompleter(commandManager.getCommands().stream().map(Command::getName).collect(Collectors.toList())));
// Autocomplete files
consoleReader.addCompleter(new FileNameCompleter());
logger.info("Initialized");
}
Aggregations