Search in sources :

Example 1 with CommandLineImpl

use of org.apache.karaf.shell.support.parsing.CommandLineImpl in project karaf by apache.

the class JdbcParser method parse.

@Override
public CommandLine parse(Session session, String command, int cursor) {
    GogoParser parser = new GogoParser(command, cursor);
    List<String> args = parser.statement();
    List<String> nargs = new ArrayList<>();
    int state = 0;
    for (String arg : args) {
        switch(state) {
            // command
            case 0:
                nargs.add(arg);
                state = 1;
                break;
            // option or target
            case 1:
                nargs.add(arg);
                if (!arg.startsWith("-")) {
                    state = 2;
                }
                break;
            // first sql fragment
            case 2:
                nargs.add(arg);
                state = 3;
                break;
            // addtional sql
            case 3:
                nargs.set(nargs.size() - 1, nargs.get(nargs.size() - 1) + " " + arg);
                break;
        }
    }
    nargs.set(nargs.size() - 1, "\"" + nargs.get(nargs.size() - 1) + "\"");
    return new CommandLineImpl(nargs.toArray(new String[nargs.size()]), parser.cursorArgumentIndex(), Math.max(parser.argumentPosition(), nargs.size()), cursor, command.substring(0, parser.position()));
}
Also used : GogoParser(org.apache.karaf.shell.support.parsing.GogoParser) ArrayList(java.util.ArrayList) CommandLineImpl(org.apache.karaf.shell.support.parsing.CommandLineImpl)

Aggregations

ArrayList (java.util.ArrayList)1 CommandLineImpl (org.apache.karaf.shell.support.parsing.CommandLineImpl)1 GogoParser (org.apache.karaf.shell.support.parsing.GogoParser)1