Jian Li | cd806b0 | 2018-07-19 02:39:47 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | * |
| 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 |
| 7 | * |
| 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. |
| 15 | */ |
| 16 | package org.onosproject.openstacknetworking.cli; |
| 17 | |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 18 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
| 19 | import org.apache.karaf.shell.api.console.CommandLine; |
| 20 | import org.apache.karaf.shell.api.console.Completer; |
| 21 | import org.apache.karaf.shell.api.console.Session; |
| 22 | import org.apache.karaf.shell.support.completers.StringsCompleter; |
Jian Li | cd806b0 | 2018-07-19 02:39:47 +0900 | [diff] [blame] | 23 | import org.onosproject.openstacknetworking.api.InstancePort; |
| 24 | import org.onosproject.openstacknetworking.api.InstancePortService; |
| 25 | |
| 26 | import java.util.List; |
| 27 | import java.util.Set; |
| 28 | import java.util.SortedSet; |
| 29 | import java.util.stream.Collectors; |
| 30 | |
| 31 | import static org.onosproject.cli.AbstractShellCommand.get; |
| 32 | |
| 33 | /** |
| 34 | * Instance port ID completer. |
| 35 | */ |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 36 | @Service |
Jian Li | cd806b0 | 2018-07-19 02:39:47 +0900 | [diff] [blame] | 37 | public class InstancePortIdCompleter implements Completer { |
| 38 | |
| 39 | @Override |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 40 | public int complete(Session session, CommandLine commandLine, List<String> candidates) { |
Jian Li | cd806b0 | 2018-07-19 02:39:47 +0900 | [diff] [blame] | 41 | StringsCompleter delegate = new StringsCompleter(); |
| 42 | |
| 43 | InstancePortService service = get(InstancePortService.class); |
| 44 | Set<String> portIds = service.instancePorts().stream() |
| 45 | .map(InstancePort::portId).collect(Collectors.toSet()); |
| 46 | SortedSet<String> strings = delegate.getStrings(); |
| 47 | |
| 48 | strings.addAll(portIds); |
| 49 | |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 50 | return delegate.complete(session, commandLine, candidates); |
Jian Li | cd806b0 | 2018-07-19 02:39:47 +0900 | [diff] [blame] | 51 | } |
| 52 | } |