blob: 5d2e952c9ab462afd33ef099a6e9446b81c79b97 [file] [log] [blame]
tom0511a522014-10-04 12:06:02 -07001package org.onlab.onos.cli.net;
2
3import org.apache.karaf.shell.console.Completer;
4import org.apache.karaf.shell.console.completer.StringsCompleter;
5import org.onlab.onos.cli.AbstractShellCommand;
6import org.onlab.onos.net.intent.Intent;
7import org.onlab.onos.net.intent.IntentService;
8
9import java.util.Iterator;
10import java.util.List;
11import java.util.SortedSet;
12
13/**
14 * Intent ID completer.
15 */
16public class IntentIdCompleter implements Completer {
17 @Override
18 public int complete(String buffer, int cursor, List<String> candidates) {
19 // Delegate string completer
20 StringsCompleter delegate = new StringsCompleter();
21
22 // Fetch our service and feed it's offerings to the string completer
23 IntentService service = AbstractShellCommand.get(IntentService.class);
24 Iterator<Intent> it = service.getIntents().iterator();
25 SortedSet<String> strings = delegate.getStrings();
26 while (it.hasNext()) {
tom85258ee2014-10-07 00:10:02 -070027 strings.add(it.next().id().toString());
tom0511a522014-10-04 12:06:02 -070028 }
29
30 // Now let the completer do the work for figuring out what to offer.
31 return delegate.complete(buffer, cursor, candidates);
32 }
33
34}