Search in sources :

Example 1 with SubCommand

use of de.jackwhite20.japs.server.command.impl.sub.SubCommand 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");
}
Also used : PrintStream(java.io.PrintStream) JaPSLogger(de.jackwhite20.japs.server.logging.JaPSLogger) SubCommand(de.jackwhite20.japs.server.command.impl.sub.SubCommand) ConsoleReader(jline.console.ConsoleReader) LoggingOutputStream(de.jackwhite20.japs.server.logging.out.LoggingOutputStream) IOException(java.io.IOException) FileNameCompleter(jline.console.completer.FileNameCompleter) CommandManager(de.jackwhite20.japs.server.command.CommandManager) StringsCompleter(jline.console.completer.StringsCompleter)

Aggregations

CommandManager (de.jackwhite20.japs.server.command.CommandManager)1 SubCommand (de.jackwhite20.japs.server.command.impl.sub.SubCommand)1 JaPSLogger (de.jackwhite20.japs.server.logging.JaPSLogger)1 LoggingOutputStream (de.jackwhite20.japs.server.logging.out.LoggingOutputStream)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 ConsoleReader (jline.console.ConsoleReader)1 FileNameCompleter (jline.console.completer.FileNameCompleter)1 StringsCompleter (jline.console.completer.StringsCompleter)1