blob: e0d183de496a899395ff709363e9d2a8bdbeba3e [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 java.util.Collections;
19import java.util.List;
20import java.util.Set;
21import java.util.stream.Collectors;
22
HIGUCHI Yuta4f074c02015-11-23 10:15:53 -080023import org.onosproject.cli.AbstractChoicesCompleter;
24import org.onosproject.cli.AbstractShellCommand;
25import org.onosproject.net.config.NetworkConfigRegistry;
26import org.onosproject.net.config.SubjectFactory;
27
28/**
29 * Network configuration subject key completer.
30 *
31 * Assumes argument right before the one being completed is SubjectClassKey.
32 */
33public class SubjectKeyCompleter extends AbstractChoicesCompleter {
34
35 @Override
36 protected List<String> choices() {
37 NetworkConfigRegistry service = AbstractShellCommand.get(NetworkConfigRegistry.class);
Ray Milkeyd84f89b2018-08-17 14:54:17 -070038 String subjectClassKey = commandLine.getArguments()[commandLine.getCursorArgumentIndex() - 1];
HIGUCHI Yuta4f074c02015-11-23 10:15:53 -080039
40 SubjectFactory subjectFactory = service.getSubjectFactory(subjectClassKey);
41 if (subjectFactory == null) {
42 return Collections.emptyList();
43 }
44 // get all registered subject objects.
45 Set<Object> subjects = service.getSubjects(subjectFactory.subjectClass());
46 return subjects.stream().map(subjectFactory::subjectKey).collect(Collectors.toList());
47 }
48
49}