use of org.apache.karaf.shell.support.completers.ArgumentCommandLine in project karaf by apache.
the class ArgumentCompleter method verifyCompleter.
protected boolean verifyCompleter(Session session, Completer completer, String argument) {
List<Candidate> candidates = new ArrayList<>();
completer.completeCandidates(session, new ArgumentCommandLine(argument, argument.length()), candidates);
return !candidates.isEmpty();
}
use of org.apache.karaf.shell.support.completers.ArgumentCommandLine 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();
}
};
}
Aggregations