blob: 5b3d338b2eafe652c6ac8ef687f35d20f2274fe4 [file] [log] [blame]
Daniele Moro94660a02019-12-02 12:02:07 -08001/*
Joey Armstrong0964a2c2023-01-05 14:26:05 -05002 * Copyright 2019-2023 Open Networking Foundation (ONF) and the ONF Contributors
Daniele Moro94660a02019-12-02 12:02:07 -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.opencord.bng.cli;
17
18import 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;
23import org.onosproject.cli.AbstractShellCommand;
24import org.opencord.bng.BngService;
25
26import java.util.List;
27import java.util.SortedSet;
28
29/**
30 * Attachment Key completer.
31 */
32@Service
33public class AttachmentKeyCompleter implements Completer {
34
35 @Override
36 public int complete(Session session, CommandLine commandLine, List<String> candidates) {
37 // Delegate string completer
38 StringsCompleter delegate = new StringsCompleter();
39
40 BngService service = AbstractShellCommand.get(BngService.class);
41 SortedSet<String> strings = delegate.getStrings();
42 service.getAttachments().keySet().forEach(strings::add);
43 // Now let the completer do the work for figuring out what to offer.
44 return delegate.complete(session, commandLine, candidates);
45 }
46}