tom | 0511a52 | 2014-10-04 12:06:02 -0700 | [diff] [blame] | 1 | package org.onlab.onos.cli.net; |
| 2 | |
| 3 | import org.apache.karaf.shell.console.Completer; |
| 4 | import org.apache.karaf.shell.console.completer.StringsCompleter; |
| 5 | import org.onlab.onos.cli.AbstractShellCommand; |
| 6 | import org.onlab.onos.net.intent.Intent; |
| 7 | import org.onlab.onos.net.intent.IntentService; |
| 8 | |
| 9 | import java.util.Iterator; |
| 10 | import java.util.List; |
| 11 | import java.util.SortedSet; |
| 12 | |
| 13 | /** |
| 14 | * Intent ID completer. |
| 15 | */ |
| 16 | public 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()) { |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 27 | strings.add(it.next().id().toString()); |
tom | 0511a52 | 2014-10-04 12:06:02 -0700 | [diff] [blame] | 28 | } |
| 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 | } |