Search in sources :

Example 1 with AppCommandParser

use of org.neo4j.shell.AppCommandParser in project neo4j by neo4j.

the class AbstractAppServer method tabComplete.

@Override
public TabCompletion tabComplete(Serializable clientID, String partOfLine) throws ShellException, RemoteException {
    // TODO We can't assume it's an AppShellServer, can we?
    try {
        AppCommandParser parser = new AppCommandParser(this, partOfLine);
        App app = parser.app();
        List<String> appCandidates = app.completionCandidates(partOfLine, getClientSession(clientID));
        appCandidates = quote(appCandidates);
        if (appCandidates.size() == 1) {
            appCandidates.set(0, appCandidates.get(0) + " ");
        }
        int cursor = partOfLine.length() - TextUtil.lastWordOrQuoteOf(partOfLine, true).length();
        return new TabCompletion(appCandidates, cursor);
    } catch (Exception e) {
        throw wrapException(e);
    }
}
Also used : App(org.neo4j.shell.App) TabCompletion(org.neo4j.shell.TabCompletion) AppCommandParser(org.neo4j.shell.AppCommandParser) RemoteException(java.rmi.RemoteException) ShellException(org.neo4j.shell.ShellException)

Example 2 with AppCommandParser

use of org.neo4j.shell.AppCommandParser in project neo4j by neo4j.

the class Dump method newParser.

private AppCommandParser newParser(AppCommandParser parser) throws ShellException {
    String newLine = parser.getLineWithoutApp();
    AppCommandParser newParser = newParser(newLine);
    newParser.options().putAll(parser.options());
    return newParser;
}
Also used : AppCommandParser(org.neo4j.shell.AppCommandParser)

Example 3 with AppCommandParser

use of org.neo4j.shell.AppCommandParser in project neo4j by neo4j.

the class CdTest method shouldProvideTabCompletions.

@Test
public void shouldProvideTabCompletions() throws Exception {
    // GIVEN
    Node root = createNodeWithSomeSubNodes("Mattias", "Magnus", "Tobias");
    Cd app = (Cd) server.findApp("cd");
    app.execute(new AppCommandParser(server, "cd -a " + root.getId()), session, silence);
    // WHEN
    List<String> candidates = app.completionCandidates("cd Ma", session);
    // THEN
    assertHasCandidate(candidates, "Mattias");
    assertHasCandidate(candidates, "Magnus");
}
Also used : Node(org.neo4j.graphdb.Node) AppCommandParser(org.neo4j.shell.AppCommandParser) Test(org.junit.Test)

Example 4 with AppCommandParser

use of org.neo4j.shell.AppCommandParser in project neo4j by neo4j.

the class AbstractAppServer method interpretLine.

@Override
public Response interpretLine(Serializable clientId, String line, Output out) throws ShellException {
    Session session = getClientSession(clientId);
    if (line == null || line.trim().length() == 0) {
        return new Response(getPrompt(session), Continuation.INPUT_COMPLETE);
    }
    try {
        Continuation commandResult = null;
        for (String command : line.split(Pattern.quote("&&"))) {
            command = TextUtil.removeSpaces(command);
            command = replaceAlias(command, session);
            AppCommandParser parser = new AppCommandParser(this, command);
            commandResult = parser.app().execute(parser, session, out);
        }
        return new Response(getPrompt(session), commandResult);
    } catch (Exception e) {
        throw wrapException(e);
    }
}
Also used : Response(org.neo4j.shell.Response) Continuation(org.neo4j.shell.Continuation) AppCommandParser(org.neo4j.shell.AppCommandParser) RemoteException(java.rmi.RemoteException) ShellException(org.neo4j.shell.ShellException) Session(org.neo4j.shell.Session)

Example 5 with AppCommandParser

use of org.neo4j.shell.AppCommandParser in project neo4j by neo4j.

the class Dump method execute.

@Override
public Continuation execute(AppCommandParser parser, Session session, Output out) throws Exception {
    if (// Dump the whole graph
    parser.arguments().isEmpty()) {
        try (Transaction tx = getServer().getDb().beginTransaction(implicit, AUTH_DISABLED)) {
            getServer().registerTopLevelTransactionInProgress(session.getId());
            final SubGraph graph = DatabaseSubGraph.from(getServer().getDb());
            export(graph, out);
            tx.success();
            return Continuation.INPUT_COMPLETE;
        }
    } else {
        AppCommandParser newParser = newParser(parser);
        return super.execute(newParser, session, out);
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) AppCommandParser(org.neo4j.shell.AppCommandParser) SubGraph(org.neo4j.cypher.export.SubGraph) DatabaseSubGraph(org.neo4j.cypher.export.DatabaseSubGraph) CypherResultSubGraph(org.neo4j.cypher.export.CypherResultSubGraph)

Aggregations

AppCommandParser (org.neo4j.shell.AppCommandParser)5 RemoteException (java.rmi.RemoteException)2 ShellException (org.neo4j.shell.ShellException)2 Test (org.junit.Test)1 CypherResultSubGraph (org.neo4j.cypher.export.CypherResultSubGraph)1 DatabaseSubGraph (org.neo4j.cypher.export.DatabaseSubGraph)1 SubGraph (org.neo4j.cypher.export.SubGraph)1 Node (org.neo4j.graphdb.Node)1 Transaction (org.neo4j.graphdb.Transaction)1 App (org.neo4j.shell.App)1 Continuation (org.neo4j.shell.Continuation)1 Response (org.neo4j.shell.Response)1 Session (org.neo4j.shell.Session)1 TabCompletion (org.neo4j.shell.TabCompletion)1