Search in sources :

Example 1 with ArgumentCompletor

use of jline.ArgumentCompletor in project GNS by MobilityFirst.

the class ConsoleModule method loadCompletor.

/**
   * Loads the commands for this module
   */
protected void loadCompletor() {
    List<Completor> completors = new LinkedList<>();
    int size = commands.size();
    if (size > 0) {
        TreeSet<String> set = new TreeSet<>();
        Iterator<ConsoleCommand> it = commands.iterator();
        while (it.hasNext()) {
            set.add(it.next().getCommandName());
        }
        completors.add(new SimpleCompletor(set.toArray(new String[size])));
    }
    completors.add(new FileNameCompletor());
    Completor[] completorsArray = completors.toArray(new Completor[completors.size()]);
    consoleCompletor = new ArgumentCompletor(completorsArray, new CommandDelimiter());
}
Also used : FileNameCompletor(jline.FileNameCompletor) ArgumentCompletor(jline.ArgumentCompletor) ConsoleCommand(edu.umass.cs.gnsclient.console.commands.ConsoleCommand) LinkedList(java.util.LinkedList) TreeSet(java.util.TreeSet) SimpleCompletor(jline.SimpleCompletor) SimpleCompletor(jline.SimpleCompletor) ArgumentCompletor(jline.ArgumentCompletor) FileNameCompletor(jline.FileNameCompletor) Completor(jline.Completor)

Example 2 with ArgumentCompletor

use of jline.ArgumentCompletor in project jackrabbit by apache.

the class JcrClient method runInteractive.

/**
     * Run in interactive mode
     * @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() + "] > ");
            if (input == null) {
                input = "exit";
            } else {
                input = input.trim();
            }
            log.debug("running: " + input);
            if (input.equals("exit") || input.equals("quit")) {
                // exit?
                exit = true;
                System.out.println("Good bye...");
            } else if (input.length() > 0) {
                this.runCommand(input);
            }
        } catch (JcrParserException e) {
            System.out.println(e.getLocalizedMessage());
            System.out.println();
        } catch (Exception e) {
            handleException(reader, e);
        }
    }
}
Also used : ConsoleReader(jline.ConsoleReader) ArrayList(java.util.ArrayList) ArgumentCompletor(jline.ArgumentCompletor) History(jline.History) RepositoryException(javax.jcr.RepositoryException) InvalidItemStateException(javax.jcr.InvalidItemStateException) CommandException(org.apache.jackrabbit.standalone.cli.CommandException) IOException(java.io.IOException) ParseException(org.apache.commons.cli.ParseException) SimpleCompletor(jline.SimpleCompletor) SimpleCompletor(jline.SimpleCompletor) ArgumentCompletor(jline.ArgumentCompletor) Completor(jline.Completor)

Aggregations

ArgumentCompletor (jline.ArgumentCompletor)2 Completor (jline.Completor)2 SimpleCompletor (jline.SimpleCompletor)2 ConsoleCommand (edu.umass.cs.gnsclient.console.commands.ConsoleCommand)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 TreeSet (java.util.TreeSet)1 InvalidItemStateException (javax.jcr.InvalidItemStateException)1 RepositoryException (javax.jcr.RepositoryException)1 ConsoleReader (jline.ConsoleReader)1 FileNameCompletor (jline.FileNameCompletor)1 History (jline.History)1 ParseException (org.apache.commons.cli.ParseException)1 CommandException (org.apache.jackrabbit.standalone.cli.CommandException)1