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