Search in sources :

Example 1 with GraqlShellOptions

use of ai.grakn.graql.shell.GraqlShellOptions in project grakn by graknlabs.

the class GraqlShellIT method runShell.

private ShellResponse runShell(String input, String... args) throws Exception {
    args = addKeyspaceAndUriParams(args);
    InputStream in = new ByteArrayInputStream(input.getBytes());
    OutputStream bout = new ByteArrayOutputStream();
    OutputStream berr = new ByteArrayOutputStream();
    OutputStream tout = bout;
    OutputStream terr = berr;
    if (showStdOutAndErr) {
        // Intercept stdout and stderr, but make sure it is still printed using the TeeOutputStream
        tout = new TeeOutputStream(bout, System.out);
        terr = new TeeOutputStream(berr, System.err);
    }
    PrintStream out = new PrintStream(tout);
    PrintStream err = new PrintStream(terr);
    Boolean success = null;
    GraknConfig config = GraknConfig.create();
    try {
        System.setIn(in);
        GraqlShellOptions options = GraqlShellOptions.create(args);
        success = GraqlConsole.start(options, new GraknSessionProvider(config), historyFile, out, err);
    } catch (Exception e) {
        e.printStackTrace();
        err.flush();
        fail(berr.toString());
    } finally {
        resetIO();
    }
    out.flush();
    err.flush();
    assertNotNull(success);
    return ShellResponse.of(bout.toString(), berr.toString(), success);
}
Also used : GraknSessionProvider(ai.grakn.graql.shell.GraknSessionProvider) PrintStream(java.io.PrintStream) TeeOutputStream(org.apache.commons.io.output.TeeOutputStream) GraknConfig(ai.grakn.engine.GraknConfig) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) GraqlShellOptions(ai.grakn.graql.shell.GraqlShellOptions) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TeeOutputStream(org.apache.commons.io.output.TeeOutputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 2 with GraqlShellOptions

use of ai.grakn.graql.shell.GraqlShellOptions in project grakn by graknlabs.

the class Graql method run.

public void run(String[] args) throws IOException, InterruptedException {
    String context = args.length > 0 ? args[0] : "";
    switch(context) {
        case "console":
            GraqlShellOptions options;
            try {
                options = graqlShellOptionsFactory.createGraqlShellOptions(valuesFrom(args, 1));
            } catch (ParseException e) {
                System.err.println(e.getMessage());
                return;
            }
            GraqlConsole.start(options, sessionProvider, HISTORY_FILENAME, System.out, System.err);
            break;
        case "migrate":
            migrate(valuesFrom(args, 1));
            break;
        case "version":
            version();
            break;
        default:
            help();
    }
}
Also used : GraqlShellOptions(ai.grakn.graql.shell.GraqlShellOptions) ParseException(org.apache.commons.cli.ParseException)

Aggregations

GraqlShellOptions (ai.grakn.graql.shell.GraqlShellOptions)2 GraknConfig (ai.grakn.engine.GraknConfig)1 GraknSessionProvider (ai.grakn.graql.shell.GraknSessionProvider)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 PrintStream (java.io.PrintStream)1 ParseException (org.apache.commons.cli.ParseException)1 TeeOutputStream (org.apache.commons.io.output.TeeOutputStream)1