blob: 55baaf690311b17bbdfe2d1be3735e28f2783b49 [file] [log] [blame]
HIGUCHI Yuta4f074c02015-11-23 10:15:53 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
HIGUCHI Yuta4f074c02015-11-23 10:15:53 -08003 *
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.cli.cfg;
17
18import static com.google.common.base.Preconditions.checkArgument;
19
20import java.util.List;
21import java.util.Set;
22import java.util.stream.Collectors;
23
HIGUCHI Yuta4f074c02015-11-23 10:15:53 -080024import org.onosproject.cli.AbstractChoicesCompleter;
25import org.onosproject.cli.AbstractShellCommand;
26import org.onosproject.net.config.Config;
27import org.onosproject.net.config.NetworkConfigRegistry;
28import org.onosproject.net.config.SubjectFactory;
29
30import com.google.common.collect.ImmutableList;
31
32/**
33 * Network configuration config key completer.
34 *
35 * Assumes 2 argument before the one being completed is SubjectClassKey
36 * and argument right before the one being completed is SubjectKey.
37 */
38public class ConfigKeyCompleter extends AbstractChoicesCompleter {
39
40 // FIXME ConfigKeyCompleter never gets called??
41 @Override
42 protected List<String> choices() {
43 NetworkConfigRegistry service = AbstractShellCommand.get(NetworkConfigRegistry.class);
HIGUCHI Yuta4f074c02015-11-23 10:15:53 -080044
Ray Milkeyd84f89b2018-08-17 14:54:17 -070045 checkArgument(commandLine.getCursorArgumentIndex() >= 2);
46 String subjectClassKey = commandLine.getArguments()[commandLine.getCursorArgumentIndex() - 2];
HIGUCHI Yuta4f074c02015-11-23 10:15:53 -080047
48 SubjectFactory<?> subjectFactory = service.getSubjectFactory(subjectClassKey);
49 if (subjectFactory == null) {
50 return ImmutableList.of();
51 }
52
Ray Milkeyd84f89b2018-08-17 14:54:17 -070053 String subjectKey = commandLine.getArguments()[commandLine.getCursorArgumentIndex() - 1];
HIGUCHI Yuta4f074c02015-11-23 10:15:53 -080054
55 Object subject = subjectFactory.createSubject(subjectKey);
56 Set<? extends Config<Object>> configs = service.getConfigs(subject);
57 return configs.stream().map(Config::key).collect(Collectors.toList());
58 }
59
60}