tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 1 | package org.onlab.onos.cli; |
| 2 | |
| 3 | import org.apache.karaf.shell.console.Completer; |
| 4 | import org.apache.karaf.shell.console.completer.StringsCompleter; |
| 5 | import org.onlab.onos.net.GreetService; |
| 6 | |
| 7 | import java.util.Iterator; |
| 8 | import java.util.List; |
| 9 | import java.util.SortedSet; |
| 10 | |
| 11 | /** |
| 12 | * Simple example of a command-line parameter completer. |
| 13 | * For a more open-ended sets a more efficient implementation would be required. |
| 14 | */ |
| 15 | public class NameCompleter implements Completer { |
| 16 | @Override |
| 17 | public int complete(String buffer, int cursor, List<String> candidates) { |
| 18 | // Delegate string completer |
| 19 | StringsCompleter delegate = new StringsCompleter(); |
| 20 | |
| 21 | // Fetch our service and feed it's offerings to the string completer |
| 22 | GreetService greetService = AbstractShellCommand.get(GreetService.class); |
| 23 | Iterator<String> it = greetService.names().iterator(); |
| 24 | SortedSet<String> strings = delegate.getStrings(); |
| 25 | while (it.hasNext()) { |
| 26 | strings.add(it.next()); |
| 27 | } |
| 28 | |
| 29 | // Now let the completer do the work for figuring out what to offer. |
| 30 | return delegate.complete(buffer, cursor, candidates); |
| 31 | } |
| 32 | |
| 33 | } |