blob: c53098ddee1c3559b41b57996180b2a8f2cdf511 [file] [log] [blame]
Jian Li26ef1302018-07-04 14:37:06 +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.openstackvtap.cli;
17
18import org.apache.karaf.shell.console.Completer;
19import org.apache.karaf.shell.console.completer.StringsCompleter;
20import org.onosproject.cli.AbstractShellCommand;
21import org.onosproject.openstackvtap.api.OpenstackVtap;
22import org.onosproject.openstackvtap.api.OpenstackVtapService;
23
24import java.util.List;
25import java.util.SortedSet;
26
27import static org.onosproject.openstackvtap.util.OpenstackVtapUtil.getVtapTypeFromString;
28
29/**
30 * vTap ID completer.
31 */
32public class VtapIdCompleter implements Completer {
33
34 private static final String VTAP_TYPE = "none";
35
36 @Override
37 public int complete(String buffer, int cursor, List<String> candidates) {
38
39 OpenstackVtap.Type type = getVtapTypeFromString(VTAP_TYPE);
40
41 // Delegate string completer
42 StringsCompleter delegate = new StringsCompleter();
43 SortedSet<String> strings = delegate.getStrings();
44
45 OpenstackVtapService service = AbstractShellCommand.get(OpenstackVtapService.class);
46
47 service.getVtaps(type).forEach(t -> {
48 strings.add(t.id().toString());
49 });
50
51 return delegate.complete(buffer, cursor, candidates);
52 }
53}