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()));
}
Aggregations