Lee Yongjae | 6dc7e4f | 2017-12-06 16:17:51 +0900 | [diff] [blame] | 1 | /* |
Jian Li | 8df54a9 | 2018-08-23 17:01:31 +0900 | [diff] [blame] | 2 | * Copyright 2018-present Open Networking Foundation |
Lee Yongjae | 6dc7e4f | 2017-12-06 16:17:51 +0900 | [diff] [blame] | 3 | * |
| 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 | */ |
Jian Li | 8df54a9 | 2018-08-23 17:01:31 +0900 | [diff] [blame] | 16 | package org.onosproject.simplefabric.cli; |
Lee Yongjae | 6dc7e4f | 2017-12-06 16:17:51 +0900 | [diff] [blame] | 17 | |
| 18 | import com.google.common.collect.Lists; |
| 19 | import org.apache.karaf.shell.console.completer.ArgumentCompleter; |
| 20 | import org.onosproject.cli.AbstractChoicesCompleter; |
| 21 | |
| 22 | import java.util.List; |
| 23 | import java.util.Arrays; |
| 24 | import java.util.Collections; |
| 25 | |
| 26 | /** |
| 27 | * SimpleFabric command completer. |
| 28 | */ |
| 29 | public class SimpleFabricCommandCompleter extends AbstractChoicesCompleter { |
| 30 | |
Ray Milkey | 10f35dc | 2018-02-01 09:26:51 -0800 | [diff] [blame] | 31 | private static final List<String> COMMAND_LIST = |
Lee Yongjae | 6dc7e4f | 2017-12-06 16:17:51 +0900 | [diff] [blame] | 32 | Arrays.asList("show", "intents", "reactive-intents", "refresh", "flush"); |
| 33 | |
| 34 | @Override |
| 35 | public List<String> choices() { |
| 36 | ArgumentCompleter.ArgumentList argumentList = getArgumentList(); |
| 37 | if (argumentList == null) { |
| 38 | return Collections.emptyList(); |
| 39 | } |
| 40 | List<String> argList = Lists.newArrayList(argumentList.getArguments()); |
| 41 | String argOne = null; |
| 42 | if (argList.size() > 1) { |
| 43 | argOne = argList.get(1); |
| 44 | } |
| 45 | if (COMMAND_LIST.contains(argOne)) { |
| 46 | return Collections.emptyList(); |
| 47 | } else { |
| 48 | return COMMAND_LIST; |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |