@Override public List<String> words() { return Arrays.asList(cmdLine.getArguments()); } @Override
@Override public String word() { return cmdLine.getCursorArgument(); } @Override
default void completeCandidates(Session session, CommandLine commandLine, List<Candidate> candidates) { List<String> strings = new ArrayList<>(); int idx = complete(session, commandLine, strings); String word = ""; if (idx > commandLine.getBufferPosition() - commandLine.getArgumentPosition()) { word = commandLine.getBuffer().substring(commandLine.getBufferPosition() - commandLine.getArgumentPosition(), idx); } for (String string : strings) { String str = word + string; if (str.endsWith(" ")) { candidates.add(new Candidate(str.substring(0, str.length() - 1), true)); } else { candidates.add(new Candidate(word + string, false)); } } } }
@Override protected List<String> choices() { NetworkConfigRegistry service = AbstractShellCommand.get(NetworkConfigRegistry.class); checkArgument(commandLine.getCursorArgumentIndex() >= 2); String subjectClassKey = commandLine.getArguments()[commandLine.getCursorArgumentIndex() - 2]; SubjectFactory<?> subjectFactory = service.getSubjectFactory(subjectClassKey); if (subjectFactory == null) { return ImmutableList.of(); } String subjectKey = commandLine.getArguments()[commandLine.getCursorArgumentIndex() - 1]; Object subject = subjectFactory.createSubject(subjectKey); Set<? extends Config<Object>> configs = service.getConfigs(subject); return configs.stream().map(Config::key).collect(Collectors.toList()); }
@Override public int complete(Session session, CommandLine commandLine, List<String> candidates) { String[] args = commandLine.getArguments(); int argIndex = commandLine.getCursorArgumentIndex(); StringsCompleter completer = new StringsCompleter(getNames(session)); if (argIndex == 0) { int res = completer.complete(session, new ArgumentCommandLine(args[argIndex], commandLine.getArgumentPosition()), candidates); if (res > -1) { res += commandLine.getBufferPosition() - commandLine.getArgumentPosition(); } return res; } else if (!verifyCompleter(session, completer, args[0])) { return -1; } return 0; }
public int complete(final Session session, final CommandLine list, final List<String> candidates) { int argpos = list.getArgumentPosition(); int argIndex = list.getCursorArgumentIndex(); String[] args = list.getArguments(); int index = 0; int ret = comp.complete(list.getCursorArgument(), argpos, candidates); int pos = ret + (list.getBufferPosition() - argpos); String buffer = list.getBuffer(); int cursor = list.getBufferPosition(); if ((buffer != null) && (cursor != buffer.length()) && isDelimiter(buffer, cursor)) { for (int i = 0; i < candidates.size(); i++) {
public int complete(final Session session, final CommandLine commandLine, final List<String> candidates) { // buffer could be null assert candidates != null; String buffer = commandLine.getCursorArgument(); if (buffer == null) { buffer = ""; } else { buffer = buffer.substring(0, commandLine.getArgumentPosition()); } if (!caseSensitive) { buffer = buffer.toLowerCase(); } // KARAF-421, use getStrings() instead strings field. SortedSet<String> matches = getStrings().tailSet(buffer); for (String match : matches) { String s = caseSensitive ? match : match.toLowerCase(); if (!s.startsWith(buffer)) { break; } // noinspection unchecked candidates.add(match + " "); } return candidates.isEmpty() ? -1 : commandLine.getBufferPosition() - commandLine.getArgumentPosition(); } }
private void file(Session session, CommandLine commandLine, List<Candidate> candidates) { String buffer = commandLine.getCursorArgument(); String path = buffer.substring("file:".length(), commandLine.getArgumentPosition());
String cmd = commandLine.getArguments()[1]; if (!Strings.isNullOrEmpty(commandLine.getCursorArgument())) { List<String> suffixCandidates = strings.stream()
@Override public String line() { return cmdLine.getBuffer(); } @Override
@Override public int wordIndex() { return cmdLine.getCursorArgumentIndex(); } @Override
@Override public int cursor() { return cmdLine.getBufferPosition(); } };
@Override public int wordCursor() { return cmdLine.getArgumentPosition(); } @Override
@Override public int complete(Session session, CommandLine commandLine, List<String> candidates) { String[] args = commandLine.getArguments(); int argIndex = commandLine.getCursorArgumentIndex(); StringsCompleter completer = new StringsCompleter(getNames(session)); if (argIndex == 0) { int res = completer.complete(session, new ArgumentCommandLine(args[argIndex], commandLine.getArgumentPosition()), candidates); if (res > -1) { res += commandLine.getBufferPosition() - commandLine.getArgumentPosition(); } return res; } else if (!verifyCompleter(session, completer, args[0])) { return -1; } return 0; }
public int complete(final Session session, final CommandLine list, final List<String> candidates) { int argpos = list.getArgumentPosition(); int argIndex = list.getCursorArgumentIndex(); String[] args = list.getArguments(); int index = 0; int ret = comp.complete(list.getCursorArgument(), argpos, candidates); int pos = ret + (list.getBufferPosition() - argpos); String buffer = list.getBuffer(); int cursor = list.getBufferPosition(); if ((buffer != null) && (cursor != buffer.length()) && isDelimiter(buffer, cursor)) { for (int i = 0; i < candidates.size(); i++) {
@Override protected List<String> choices() { NetworkConfigRegistry service = AbstractShellCommand.get(NetworkConfigRegistry.class); String subjectClassKey = commandLine.getArguments()[commandLine.getCursorArgumentIndex() - 1]; SubjectFactory subjectFactory = service.getSubjectFactory(subjectClassKey); if (subjectFactory == null) { return Collections.emptyList(); } // get all registered subject objects. Set<Object> subjects = service.getSubjects(subjectFactory.subjectClass()); return subjects.stream().map(subjectFactory::subjectKey).collect(Collectors.toList()); }
@Override public int complete(Session session, CommandLine commandLine, List<String> candidates) { String arg = commandLine.getCursorArgument(); int pos = commandLine.getArgumentPosition(); CommandLine cmdLine = new DefaultParser().parse(session, arg, pos); Completer completer = session.getRegistry().getService(CommandsCompleter.class); List<String> cands = new ArrayList<>(); int res = completer.complete(session, cmdLine, cands); for (String cand : cands) { candidates.add(arg.substring(0, cmdLine.getBufferPosition() - cmdLine.getArgumentPosition()) + cand); } if (res >= 0) { res += commandLine.getBufferPosition() - commandLine.getArgumentPosition(); } return res; }
private void maven(Session session, CommandLine commandLine, List<Candidate> candidates) { String repo = System.getProperty("user.home") + "/.m2/repository"; String buffer = commandLine.getCursorArgument(); String mvn = buffer.substring("mvn:".length(), commandLine.getArgumentPosition());
@Override public String line() { return cmdLine.getBuffer(); } @Override
@Override public int wordIndex() { return cmdLine.getCursorArgumentIndex(); } @Override