Jonathan Hart | fce5147 | 2017-01-26 16:57:33 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Laboratory |
| 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 | |
| 17 | package org.onosproject.cli.net.completer; |
| 18 | |
| 19 | import org.onosproject.cli.AbstractChoicesCompleter; |
| 20 | import org.onosproject.incubator.net.intf.Interface; |
| 21 | import org.onosproject.incubator.net.intf.InterfaceService; |
| 22 | |
| 23 | import java.util.List; |
| 24 | import java.util.stream.Collectors; |
| 25 | |
| 26 | import static org.onlab.osgi.DefaultServiceDirectory.getService; |
| 27 | |
| 28 | /** |
| 29 | * Completer for interface names. |
| 30 | */ |
| 31 | public class InterfaceNameCompleter extends AbstractChoicesCompleter { |
| 32 | |
| 33 | @Override |
| 34 | protected List<String> choices() { |
| 35 | InterfaceService interfaceService = getService(InterfaceService.class); |
| 36 | |
| 37 | return interfaceService.getInterfaces().stream() |
| 38 | .map(Interface::name) |
| 39 | .filter(name -> !name.equals(Interface.NO_INTERFACE_NAME)) |
| 40 | .collect(Collectors.toList()); |
| 41 | } |
| 42 | |
| 43 | } |