Search in sources :

Example 11 with StringsCompleter

use of org.apache.karaf.shell.support.completers.StringsCompleter in project karaf by apache.

the class MyCompleter method complete.

public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    StringsCompleter delegate = new StringsCompleter();
    delegate.getStrings().add("one");
    delegate.getStrings().add("two");
    delegate.getStrings().add("three");
    return delegate.complete(session, commandLine, candidates);
}
Also used : StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter)

Example 12 with StringsCompleter

use of org.apache.karaf.shell.support.completers.StringsCompleter in project karaf by apache.

the class ConfigurationPropertyCompleter method complete.

public int complete(final Session session, final CommandLine commandLine, final List<String> candidates) {
    StringsCompleter strings = new StringsCompleter();
    if (session != null) {
        String pid = getPid(session, commandLine);
        Set<String> propertyNames = getPropertyNames(pid);
        if (propertyNames != null && !propertyNames.isEmpty()) {
            strings.getStrings().addAll(propertyNames);
        }
    }
    return strings.complete(session, commandLine, candidates);
}
Also used : StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter)

Example 13 with StringsCompleter

use of org.apache.karaf.shell.support.completers.StringsCompleter in project karaf by apache.

the class SubsystemCompleter method complete.

@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    List<String> strings = new ArrayList<>();
    for (Subsystem ss : getSubsystems()) {
        strings.add(Long.toString(ss.getSubsystemId()));
        strings.add(ss.getSymbolicName() + "/" + ss.getVersion());
    }
    return new StringsCompleter(strings).complete(session, commandLine, candidates);
}
Also used : StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter) Subsystem(org.osgi.service.subsystem.Subsystem) ArrayList(java.util.ArrayList)

Example 14 with StringsCompleter

use of org.apache.karaf.shell.support.completers.StringsCompleter in project karaf by apache.

the class HelpCommand method getCompleter.

@Override
public Completer getCompleter(final boolean scoped) {
    return new Completer() {

        @Override
        public int complete(Session session, CommandLine commandLine, List<String> candidates) {
            String[] args = commandLine.getArguments();
            int argIndex = commandLine.getCursorArgumentIndex();
            StringsCompleter completer = new StringsCompleter(Collections.singletonList(getName()));
            if (argIndex == 0) {
                return completer.complete(session, new ArgumentCommandLine(args[argIndex], commandLine.getArgumentPosition()), candidates);
            } else if (!verifyCompleter(session, completer, args[0])) {
                return -1;
            }
            // TODO: use CommandNamesCompleter and better completion wrt parsing etc...
            completer = new StringsCompleter();
            for (Command command : session.getRegistry().getCommands()) {
                if (!Session.SCOPE_GLOBAL.equals(command.getScope())) {
                    completer.getStrings().add(command.getScope() + ":" + command.getName());
                }
                completer.getStrings().add(command.getName());
            }
            completer.getStrings().add("--help");
            if (argIndex == 1) {
                int res;
                if (argIndex < args.length) {
                    res = completer.complete(session, new ArgumentCommandLine(args[argIndex], commandLine.getArgumentPosition()), candidates);
                } else {
                    res = completer.complete(session, new ArgumentCommandLine("", 0), candidates);
                }
                return res + (commandLine.getBufferPosition() - commandLine.getArgumentPosition());
            } else if (!verifyCompleter(session, completer, args[1])) {
                return -1;
            }
            return -1;
        }

        protected boolean verifyCompleter(Session session, Completer completer, String argument) {
            List<String> candidates = new ArrayList<>();
            return completer.complete(session, new ArgumentCommandLine(argument, argument.length()), candidates) != -1 && !candidates.isEmpty();
        }
    };
}
Also used : ArgumentCommandLine(org.apache.karaf.shell.support.completers.ArgumentCommandLine) CommandLine(org.apache.karaf.shell.api.console.CommandLine) ArgumentCommandLine(org.apache.karaf.shell.support.completers.ArgumentCommandLine) StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter) Command(org.apache.karaf.shell.api.console.Command) ArrayList(java.util.ArrayList) Completer(org.apache.karaf.shell.api.console.Completer) StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter) ArrayList(java.util.ArrayList) List(java.util.List) Session(org.apache.karaf.shell.api.console.Session)

Example 15 with StringsCompleter

use of org.apache.karaf.shell.support.completers.StringsCompleter in project karaf by apache.

the class CommandsCompleter method completeCandidates.

public void completeCandidates(Session session, CommandLine commandLine, List<Candidate> candidates) {
    Map<String, Completer>[] allCompleters = checkData();
    List<String> scopes = getCurrentScopes(session);
    sort(allCompleters, scopes);
    String subShell = getCurrentSubShell(session);
    String completion = getCompletionType(session);
    // SUBSHELL mode
    if (Session.COMPLETION_MODE_SUBSHELL.equalsIgnoreCase(completion)) {
        if (subShell.isEmpty()) {
            subShell = Session.SCOPE_GLOBAL;
        }
        List<Completer> completers = new ArrayList<>();
        for (String name : allCompleters[1].keySet()) {
            if (name.startsWith(subShell + ":")) {
                completers.add(allCompleters[1].get(name));
            }
        }
        if (!subShell.equals(Session.SCOPE_GLOBAL)) {
            completers.add(new StringsCompleter(new String[] { "exit" }));
        }
        completers.forEach(c -> c.completeCandidates(session, commandLine, candidates));
        return;
    }
    // FIRST mode
    if (Session.COMPLETION_MODE_FIRST.equalsIgnoreCase(completion)) {
        if (!subShell.isEmpty()) {
            List<Completer> completers = new ArrayList<>();
            for (String name : allCompleters[1].keySet()) {
                if (name.startsWith(subShell + ":")) {
                    completers.add(allCompleters[1].get(name));
                }
            }
            completers.forEach(c -> c.completeCandidates(session, commandLine, candidates));
            if (!candidates.isEmpty()) {
                return;
            }
        }
        List<Completer> compl = new ArrayList<>();
        compl.add(aliasesCompleter);
        compl.addAll(allCompleters[0].values());
        compl.forEach(c -> c.completeCandidates(session, commandLine, candidates));
        return;
    }
    List<Completer> compl = new ArrayList<>();
    compl.add(aliasesCompleter);
    compl.addAll(allCompleters[0].values());
    compl.forEach(c -> c.completeCandidates(session, commandLine, candidates));
}
Also used : StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter) ArrayList(java.util.ArrayList) Completer(org.apache.karaf.shell.api.console.Completer) StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Aggregations

StringsCompleter (org.apache.karaf.shell.support.completers.StringsCompleter)17 ArrayList (java.util.ArrayList)4 Completer (org.apache.karaf.shell.api.console.Completer)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Command (org.apache.karaf.shell.api.console.Command)2 File (java.io.File)1 Collection (java.util.Collection)1 EnumSet (java.util.EnumSet)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 CamelContext (org.apache.camel.CamelContext)1 Bus (org.apache.cxf.Bus)1 Server (org.apache.cxf.endpoint.Server)1 ServerRegistry (org.apache.cxf.endpoint.ServerRegistry)1 CommandLine (org.apache.karaf.shell.api.console.CommandLine)1 Session (org.apache.karaf.shell.api.console.Session)1 ArgumentCommandLine (org.apache.karaf.shell.support.completers.ArgumentCommandLine)1