blob: c18a0a4db75edaf7e66043e3a5ea6d3729fcc522 [file] [log] [blame]
Jian Licd806b02018-07-19 02:39:47 +09001/*
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 */
16package org.onosproject.openstacknetworking.cli;
17
18import org.apache.karaf.shell.console.Completer;
19import org.apache.karaf.shell.console.completer.StringsCompleter;
20import org.onosproject.openstacknetworking.api.InstancePort;
21import org.onosproject.openstacknetworking.api.InstancePortService;
22
23import java.util.List;
24import java.util.Set;
25import java.util.SortedSet;
26import java.util.stream.Collectors;
27
28import static org.onosproject.cli.AbstractShellCommand.get;
29
30/**
31 * Instance port ID completer.
32 */
33public class InstancePortIdCompleter implements Completer {
34
35 @Override
36 public int complete(String buffer, int cursor, List<String> candidates) {
37 StringsCompleter delegate = new StringsCompleter();
38
39 InstancePortService service = get(InstancePortService.class);
40 Set<String> portIds = service.instancePorts().stream()
41 .map(InstancePort::portId).collect(Collectors.toSet());
42 SortedSet<String> strings = delegate.getStrings();
43
44 strings.addAll(portIds);
45
46 return delegate.complete(buffer, cursor, candidates);
47 }
48}