Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.cli.net; |
alshabib | 144a294 | 2014-09-25 18:44:02 -0700 | [diff] [blame] | 17 | |
| 18 | import java.util.List; |
| 19 | import java.util.SortedSet; |
| 20 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 21 | import org.apache.karaf.shell.api.console.CommandLine; |
| 22 | import org.apache.karaf.shell.api.console.Completer; |
| 23 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
| 24 | import org.apache.karaf.shell.api.console.Session; |
| 25 | import org.apache.karaf.shell.support.completers.StringsCompleter; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 26 | import org.onosproject.net.flow.FlowEntry.FlowEntryState; |
alshabib | 144a294 | 2014-09-25 18:44:02 -0700 | [diff] [blame] | 27 | |
| 28 | /** |
Charles M.C. Chan | 6f5bdc6 | 2015-04-22 01:21:09 +0800 | [diff] [blame] | 29 | * Flow rule status completer. |
alshabib | 144a294 | 2014-09-25 18:44:02 -0700 | [diff] [blame] | 30 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 31 | @Service |
alshabib | 144a294 | 2014-09-25 18:44:02 -0700 | [diff] [blame] | 32 | public class FlowRuleStatusCompleter implements Completer { |
| 33 | @Override |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 34 | public int complete(Session session, CommandLine commandLine, List<String> candidates) { |
alshabib | 144a294 | 2014-09-25 18:44:02 -0700 | [diff] [blame] | 35 | // Delegate string completer |
| 36 | StringsCompleter delegate = new StringsCompleter(); |
| 37 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 38 | FlowEntryState[] states = FlowEntryState.values(); |
alshabib | 144a294 | 2014-09-25 18:44:02 -0700 | [diff] [blame] | 39 | SortedSet<String> strings = delegate.getStrings(); |
| 40 | for (int i = 0; i < states.length; i++) { |
| 41 | strings.add(states[i].toString().toLowerCase()); |
| 42 | } |
| 43 | strings.add(FlowsListCommand.ANY); |
| 44 | |
| 45 | // Now let the completer do the work for figuring out what to offer. |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 46 | return delegate.complete(session, commandLine, candidates); |
alshabib | 144a294 | 2014-09-25 18:44:02 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | } |