Search in sources :

Example 1 with SimpleCompletor

use of jline.SimpleCompletor in project databus by linkedin.

the class InteractiveSchemaGenerator method addArrayToCompletor.

/**
   * Add a array to autocomplete
   * @param completorArray The array to add to autocomplete
   */
private void addArrayToCompletor(String[] completorArray) {
    removeCurrentCompletor();
    if (completorArray == null || completorArray.length == 0)
        return;
    _currentCompletor = new SimpleCompletor(completorArray);
    _reader.addCompletor(_currentCompletor);
}
Also used : SimpleCompletor(jline.SimpleCompletor)

Example 2 with SimpleCompletor

use of jline.SimpleCompletor 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 3 with SimpleCompletor

use of jline.SimpleCompletor in project tomee by apache.

the class CliRunnable method run.

@Override
public void run() {
    clean();
    try {
        final StreamManager streamManager = new StreamManager(out, err, lineSep);
        final ConsoleReader reader = new ConsoleReader(sin, streamManager.getSout());
        reader.addCompletor(new FileNameCompletor());
        reader.addCompletor(new SimpleCompletor(COMMANDS.keySet().toArray(new String[COMMANDS.size()])));
        // TODO : add completers
        String line;
        final StringBuilder builtWelcome = new StringBuilder("Apache OpenEJB ").append(OpenEjbVersion.get().getVersion()).append("    build: ").append(OpenEjbVersion.get().getDate()).append("-").append(OpenEjbVersion.get().getTime()).append(lineSep);
        if (tomee) {
            builtWelcome.append(OS_LINE_SEP).append(PROPERTIES.getProperty(WELCOME_TOMEE_KEY));
        } else {
            builtWelcome.append(OS_LINE_SEP).append(PROPERTIES.getProperty(WELCOME_OPENEJB_KEY));
        }
        builtWelcome.append(lineSep).append(PROPERTIES.getProperty(WELCOME_COMMON_KEY));
        streamManager.writeOut(OpenEjbVersion.get().getUrl());
        streamManager.writeOut(builtWelcome.toString().replace("$bind", bind).replace("$port", Integer.toString(port)).replace("$name", NAME).replace(OS_LINE_SEP, lineSep));
        while ((line = reader.readLine(prompt())) != null) {
            // do we need a command for it?
            if (EXIT_COMMAND.equals(line)) {
                break;
            }
            Class<?> cmdClass = null;
            String key = null;
            for (final Map.Entry<String, Class<?>> cmd : COMMANDS.entrySet()) {
                if (line.startsWith(cmd.getKey())) {
                    cmdClass = cmd.getValue();
                    key = cmd.getKey();
                    break;
                }
            }
            if (cmdClass != null) {
                final ObjectRecipe recipe = new ObjectRecipe(cmdClass);
                recipe.setProperty("streamManager", streamManager);
                recipe.setProperty("command", line);
                recipe.setProperty("scripter", scripter);
                recipe.setProperty("commands", COMMANDS);
                recipe.allow(Option.CASE_INSENSITIVE_PROPERTIES);
                recipe.allow(Option.IGNORE_MISSING_PROPERTIES);
                recipe.allow(Option.NAMED_PARAMETERS);
                try {
                    final AbstractCommand cmdInstance = (AbstractCommand) recipe.create();
                    cmdInstance.execute(trunc(line, key));
                } catch (Exception e) {
                    streamManager.writeErr(e);
                }
            } else {
                streamManager.writeErr("sorry i don't understand '" + line + "'");
            }
        }
        clean();
    } catch (IOException e) {
        clean();
        throw new CliRuntimeException(e);
    }
}
Also used : ConsoleReader(jline.ConsoleReader) FileNameCompletor(jline.FileNameCompletor) AbstractCommand(org.apache.openejb.server.cli.command.AbstractCommand) IOException(java.io.IOException) IOException(java.io.IOException) ObjectRecipe(org.apache.xbean.recipe.ObjectRecipe) SimpleCompletor(jline.SimpleCompletor) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 4 with SimpleCompletor

use of jline.SimpleCompletor 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)

Example 5 with SimpleCompletor

use of jline.SimpleCompletor in project tomee by apache.

the class Client method main.

public static void main(final String[] args) throws Exception {
    if (args.length != 1) {
        System.err.println("Pass the base url as parameter");
        return;
    }
    final ConsoleReader reader = new ConsoleReader(System.in, new OutputStreamWriter(System.out));
    reader.addCompletor(new FileNameCompletor());
    reader.addCompletor(new SimpleCompletor(CommandManager.keys().toArray(new String[CommandManager.size()])));
    String line;
    while ((line = reader.readLine(PROMPT)) != null) {
        if (EXIT_CMD.equals(line)) {
            break;
        }
        Class<?> cmdClass = null;
        for (Map.Entry<String, Class<?>> cmd : CommandManager.getCommands().entrySet()) {
            if (line.startsWith(cmd.getKey())) {
                cmdClass = cmd.getValue();
                break;
            }
        }
        if (cmdClass != null) {
            final ObjectRecipe recipe = new ObjectRecipe(cmdClass);
            recipe.setProperty("url", args[0]);
            recipe.setProperty("command", line);
            recipe.setProperty("commands", CommandManager.getCommands());
            recipe.allow(Option.CASE_INSENSITIVE_PROPERTIES);
            recipe.allow(Option.IGNORE_MISSING_PROPERTIES);
            recipe.allow(Option.NAMED_PARAMETERS);
            try {
                final AbstractCommand cmdInstance = (AbstractCommand) recipe.create();
                cmdInstance.execute(line);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            System.err.println("sorry i don't understand '" + line + "'");
        }
    }
}
Also used : ConsoleReader(jline.ConsoleReader) ObjectRecipe(org.apache.xbean.recipe.ObjectRecipe) FileNameCompletor(jline.FileNameCompletor) SimpleCompletor(jline.SimpleCompletor) AbstractCommand(jug.client.command.api.AbstractCommand) OutputStreamWriter(java.io.OutputStreamWriter) Map(java.util.Map)

Aggregations

SimpleCompletor (jline.SimpleCompletor)5 ConsoleReader (jline.ConsoleReader)3 FileNameCompletor (jline.FileNameCompletor)3 IOException (java.io.IOException)2 Map (java.util.Map)2 ArgumentCompletor (jline.ArgumentCompletor)2 Completor (jline.Completor)2 ObjectRecipe (org.apache.xbean.recipe.ObjectRecipe)2 ConsoleCommand (edu.umass.cs.gnsclient.console.commands.ConsoleCommand)1 OutputStreamWriter (java.io.OutputStreamWriter)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 InvalidItemStateException (javax.jcr.InvalidItemStateException)1 RepositoryException (javax.jcr.RepositoryException)1 History (jline.History)1 AbstractCommand (jug.client.command.api.AbstractCommand)1 ParseException (org.apache.commons.cli.ParseException)1 CommandException (org.apache.jackrabbit.standalone.cli.CommandException)1