Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 Open Networking Laboratory |
Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 15 | */ |
Ayaka Koshibe | 43530be | 2014-09-15 11:14:52 -0700 | [diff] [blame] | 16 | package org.onlab.onos.cli.net; |
| 17 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 18 | import java.util.Iterator; |
| 19 | import java.util.List; |
| 20 | import java.util.SortedSet; |
| 21 | |
Ayaka Koshibe | 43530be | 2014-09-15 11:14:52 -0700 | [diff] [blame] | 22 | import org.apache.karaf.shell.console.Completer; |
| 23 | import org.apache.karaf.shell.console.completer.StringsCompleter; |
| 24 | import org.onlab.onos.cli.AbstractShellCommand; |
| 25 | import org.onlab.onos.net.Host; |
| 26 | import org.onlab.onos.net.host.HostService; |
| 27 | |
Ayaka Koshibe | 43530be | 2014-09-15 11:14:52 -0700 | [diff] [blame] | 28 | public class HostIdCompleter implements Completer { |
| 29 | |
| 30 | @Override |
| 31 | public int complete(String buffer, int cursor, List<String> candidates) { |
| 32 | // Delegate string completer |
| 33 | StringsCompleter delegate = new StringsCompleter(); |
| 34 | |
| 35 | HostService service = AbstractShellCommand.get(HostService.class); |
| 36 | Iterator<Host> it = service.getHosts().iterator(); |
| 37 | SortedSet<String> strings = delegate.getStrings(); |
| 38 | while (it.hasNext()) { |
| 39 | strings.add(it.next().id().toString()); |
| 40 | } |
| 41 | |
| 42 | // Now let the completer do the work for figuring out what to offer. |
| 43 | return delegate.complete(buffer, cursor, candidates); |
| 44 | |
| 45 | } |
| 46 | |
| 47 | } |