Search in sources :

Example 1 with ServerSubcommand

use of com.vaticle.typedb.core.server.parameters.ServerSubcommand in project grakn by graknlabs.

the class TypeDBServer method main.

public static void main(String[] args) {
    try {
        printASCIILogo();
        CoreConfigParser configParser = new CoreConfigParser();
        ArgsParser<ServerSubcommand> argsParser = new ArgsParser<ServerSubcommand>().subcommand(new ServerSubcommandParser.Server(configParser)).subcommand(new ServerSubcommandParser.Import()).subcommand(new ServerSubcommandParser.Export());
        Optional<ServerSubcommand> subcmd = argsParser.parse(args);
        if (subcmd.isEmpty()) {
            LOG.error(UNRECOGNISED_CLI_COMMAND.message(String.join(" ", args)));
            LOG.error(argsParser.usage());
            System.exit(1);
        } else {
            if (subcmd.get().isServer()) {
                ServerSubcommand.Server subcmdServer = subcmd.get().asServer();
                if (subcmdServer.isHelp())
                    System.out.println(argsParser.help());
                else if (subcmdServer.isVersion())
                    System.out.println("Version: " + Version.VERSION);
                else
                    runServer(subcmdServer);
            } else if (subcmd.get().isImport()) {
                importData(subcmd.get().asImport());
            } else if (subcmd.get().isExport()) {
                exportData(subcmd.get().asExport());
            } else
                throw TypeDBException.of(ILLEGAL_STATE);
        }
    } catch (Exception e) {
        if (e instanceof TypeDBException) {
            LOG.error(e.getMessage());
        } else {
            LOG.error(e.getMessage(), e);
            LOG.error(EXITED_WITH_ERROR.message());
        }
        System.exit(1);
    }
    System.exit(0);
}
Also used : TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) ServerSubcommandParser(com.vaticle.typedb.core.server.parameters.ServerSubcommandParser) CoreConfigParser(com.vaticle.typedb.core.server.parameters.CoreConfigParser) BindException(java.net.BindException) IOException(java.io.IOException) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) ServerSubcommand(com.vaticle.typedb.core.server.parameters.ServerSubcommand)

Aggregations

TypeDBException (com.vaticle.typedb.core.common.exception.TypeDBException)1 CoreConfigParser (com.vaticle.typedb.core.server.parameters.CoreConfigParser)1 ServerSubcommand (com.vaticle.typedb.core.server.parameters.ServerSubcommand)1 ServerSubcommandParser (com.vaticle.typedb.core.server.parameters.ServerSubcommandParser)1 IOException (java.io.IOException)1 BindException (java.net.BindException)1