blob: bf6a0e93f456fb3a61087e5b8abf8ae73be6c66b [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
Ray Milkey86ad7bb2018-09-27 12:32:28 -070018import org.apache.karaf.shell.api.action.lifecycle.Service;
19import org.apache.karaf.shell.api.console.CommandLine;
20import org.apache.karaf.shell.api.console.Completer;
21import org.apache.karaf.shell.api.console.Session;
22import org.apache.karaf.shell.support.completers.StringsCompleter;
Jian Licd806b02018-07-19 02:39:47 +090023import org.onosproject.openstacknetworking.api.InstancePort;
24import org.onosproject.openstacknetworking.api.InstancePortService;
25
26import java.util.List;
27import java.util.Set;
28import java.util.SortedSet;
29import java.util.stream.Collectors;
30
31import static org.onosproject.cli.AbstractShellCommand.get;
32
33/**
34 * Instance port ID completer.
35 */
Ray Milkey86ad7bb2018-09-27 12:32:28 -070036@Service
Jian Licd806b02018-07-19 02:39:47 +090037public class InstancePortIdCompleter implements Completer {
38
39 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070040 public int complete(Session session, CommandLine commandLine, List<String> candidates) {
Jian Licd806b02018-07-19 02:39:47 +090041 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 Milkey86ad7bb2018-09-27 12:32:28 -070050 return delegate.complete(session, commandLine, candidates);
Jian Licd806b02018-07-19 02:39:47 +090051 }
52}