@Override public int wordIndex() { return cmdLine.getCursorArgumentIndex(); } @Override
@Override public int wordIndex() { return cmdLine.getCursorArgumentIndex(); } @Override
@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 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) { // Delegate string completer StringsCompleter delegate = new StringsCompleter(); // Component name is the previous argument. String componentName = commandLine.getArguments()[commandLine.getCursorArgumentIndex() - 1]; ComponentConfigService service = get(ComponentConfigService.class); SortedSet<String> strings = delegate.getStrings(); Set<ConfigProperty> properties = service.getProperties(componentName); if (properties != null) { properties.forEach(property -> strings.add(property.name())); } // Now let the completer do the work for figuring out what to offer. return delegate.complete(session, commandLine, candidates); }
@Override public void completeCandidates(Session session, final CommandLine list, List<Candidate> candidates) { int argIndex = list.getCursorArgumentIndex();
@Override public void completeCandidates(Session session, final CommandLine list, List<Candidate> candidates) { int argIndex = list.getCursorArgumentIndex();
public int complete(final Session session, final CommandLine list, final List<String> candidates) { int argpos = list.getArgumentPosition(); int argIndex = list.getCursorArgumentIndex();
public int complete(final Session session, final CommandLine list, final List<String> candidates) { int argpos = list.getArgumentPosition(); int argIndex = list.getCursorArgumentIndex();
@Override public int complete(Session session, CommandLine commandLine, List<String> candidates) { // Delegate string completer StringsCompleter delegate = new StringsCompleter(); // Fetch our service and feed it's offerings to the string completer LinkService service = AbstractShellCommand.get(LinkService.class); // Link source the previous argument. String srcArg = commandLine.getArguments()[commandLine.getCursorArgumentIndex() - 1]; // Generate the device ID/port number identifiers SortedSet<String> strings = delegate.getStrings(); try { ConnectPoint src = ConnectPoint.deviceConnectPoint(srcArg); service.getEgressLinks(src) .forEach(link -> strings.add(link.dst().elementId().toString() + "/" + link.dst().port())); } catch (NumberFormatException e) { System.err.println("Invalid connect-point"); } // Now let the completer do the work for figuring out what to offer. return delegate.complete(session, commandLine, candidates); }
@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; }
@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; }
@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) {
@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) {