Ayaka Koshibe | 43530be | 2014-09-15 11:14:52 -0700 | [diff] [blame] | 1 | package org.onlab.onos.cli.net; |
| 2 | |
| 3 | import java.util.Iterator; |
| 4 | import java.util.List; |
| 5 | import java.util.SortedSet; |
| 6 | |
| 7 | import org.apache.karaf.shell.console.Completer; |
| 8 | import org.apache.karaf.shell.console.completer.StringsCompleter; |
| 9 | import org.onlab.onos.cli.AbstractShellCommand; |
| 10 | import org.onlab.onos.net.Host; |
| 11 | import org.onlab.onos.net.host.HostService; |
| 12 | |
| 13 | public class HostIdCompleter implements Completer { |
| 14 | |
| 15 | @Override |
| 16 | public int complete(String buffer, int cursor, List<String> candidates) { |
| 17 | // Delegate string completer |
| 18 | StringsCompleter delegate = new StringsCompleter(); |
| 19 | |
| 20 | HostService service = AbstractShellCommand.get(HostService.class); |
| 21 | Iterator<Host> it = service.getHosts().iterator(); |
| 22 | SortedSet<String> strings = delegate.getStrings(); |
| 23 | while (it.hasNext()) { |
| 24 | strings.add(it.next().id().toString()); |
| 25 | } |
| 26 | |
| 27 | // Now let the completer do the work for figuring out what to offer. |
| 28 | return delegate.complete(buffer, cursor, candidates); |
| 29 | |
| 30 | } |
| 31 | |
| 32 | } |