blob: 87e2cd4a6e5d87e3321dec1d8b8a5bab702be37e [file] [log] [blame]
Ray Milkey02479862015-02-17 17:02:19 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Ray Milkey02479862015-02-17 17:02:19 -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.app;
17
18import java.util.List;
Ray Milkey02479862015-02-17 17:02:19 -080019import java.util.SortedSet;
20
21import org.apache.karaf.shell.console.Completer;
22import org.apache.karaf.shell.console.completer.StringsCompleter;
23import org.onosproject.cli.AbstractShellCommand;
Ray Milkeyd088e8a2015-04-07 14:56:57 -070024import org.onosproject.net.intent.IntentService;
Ray Milkey02479862015-02-17 17:02:19 -080025
26/**
27 * Application name completer.
28 */
Ray Milkeyd088e8a2015-04-07 14:56:57 -070029public class ApplicationIdWithIntentNameCompleter implements Completer {
Ray Milkey02479862015-02-17 17:02:19 -080030 @Override
31 public int complete(String buffer, int cursor, List<String> candidates) {
32 // Delegate string completer
33 StringsCompleter delegate = new StringsCompleter();
34
35 // Fetch our service and feed it's offerings to the string completer
Ray Milkeyd088e8a2015-04-07 14:56:57 -070036 IntentService service = AbstractShellCommand.get(IntentService.class);
Ray Milkey02479862015-02-17 17:02:19 -080037 SortedSet<String> strings = delegate.getStrings();
Ray Milkeyd088e8a2015-04-07 14:56:57 -070038
39 service.getIntents()
40 .forEach(intent ->
41 strings.add(intent.appId().name()));
Ray Milkey02479862015-02-17 17:02:19 -080042
43 // Now let the completer do the work for figuring out what to offer.
44 return delegate.complete(buffer, cursor, candidates);
45 }
46
47}