blob: 7ef407eecca20e28d71d05d0b1eee2f5e428fb5c [file] [log] [blame]
Thomas Vachuska7d693f52014-10-21 19:17:57 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
tom1380eee2014-09-24 09:22:02 -070019package org.onlab.onos.cli;
20
21import org.apache.karaf.shell.console.Completer;
22import org.apache.karaf.shell.console.completer.StringsCompleter;
23import org.onlab.onos.cluster.ClusterService;
24import org.onlab.onos.cluster.ControllerNode;
25
26import java.util.Iterator;
27import java.util.List;
28import java.util.SortedSet;
29
30/**
31 * Node ID completer.
32 */
33public class NodeIdCompleter implements Completer {
34 @Override
35 public int complete(String buffer, int cursor, List<String> candidates) {
36 // Delegate string completer
37 StringsCompleter delegate = new StringsCompleter();
38
39 // Fetch our service and feed it's offerings to the string completer
40 ClusterService service = AbstractShellCommand.get(ClusterService.class);
41 Iterator<ControllerNode> it = service.getNodes().iterator();
42 SortedSet<String> strings = delegate.getStrings();
43 while (it.hasNext()) {
44 strings.add(it.next().id().toString());
45 }
46
47 // Now let the completer do the work for figuring out what to offer.
48 return delegate.complete(buffer, cursor, candidates);
49 }
50
51}