* @throws Exception
* if an Exception occurs
*/
public void runInteractive() throws Exception {
// built jline console reader with history + tab completion
ConsoleReader reader = new ConsoleReader();
reader.setHistory(new History());
reader.setUseHistory(true);
// get all available commands for command tab completion
Collection<CommandLine> commands =
CommandLineFactory.getInstance().getCommandLines();
List<String> commandNames = new ArrayList<String>();
for (CommandLine c : commands) {
commandNames.add(c.getName());
for (Object alias : c.getAlias()) {
commandNames.add((String) alias);
}
}
commandNames.add("exit");
commandNames.add("quit");
// first part is the command, then all arguments will get children tab completion
reader.addCompletor(new ArgumentCompletor( new Completor[] {
new SimpleCompletor(commandNames.toArray(new String[] {} )),
new JcrChildrenCompletor()
}));
while (!exit) {
try {
String input = reader.readLine("[" + this.getPrompt() + "] > ");
log.debug("running: " + input);
if (input.trim().equals("exit") || input.trim().equals("quit")) { // exit?
exit = true;
System.out.println("Good bye...");