Search in sources :

Example 1 with GraknSessionProvider

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

the class Graql method main.

/**
 * Invocation from bash script 'graql'
 *
 * @param args
 */
public static void main(String[] args) throws IOException, InterruptedException {
    GraknSessionProvider sessionProvider = new GraknSessionProvider(GraknConfig.create());
    GraqlShellOptionsFactory graqlShellOptionsFactory = GraqlShellOptions::create;
    new Graql(sessionProvider, graqlShellOptionsFactory).run(args);
}
Also used : GraknSessionProvider(ai.grakn.graql.shell.GraknSessionProvider) GraqlShellOptionsFactory(ai.grakn.graql.shell.GraqlShellOptionsFactory)

Example 2 with GraknSessionProvider

use of ai.grakn.graql.shell.GraknSessionProvider 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)

Aggregations

GraknSessionProvider (ai.grakn.graql.shell.GraknSessionProvider)2 GraknConfig (ai.grakn.engine.GraknConfig)1 GraqlShellOptions (ai.grakn.graql.shell.GraqlShellOptions)1 GraqlShellOptionsFactory (ai.grakn.graql.shell.GraqlShellOptionsFactory)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 TeeOutputStream (org.apache.commons.io.output.TeeOutputStream)1