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; |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 19 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Lee Yongjae | 6dc7e4f | 2017-12-06 16:17:51 +0900 | [diff] [blame] | 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 | */ |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 29 | @Service |
Lee Yongjae | 6dc7e4f | 2017-12-06 16:17:51 +0900 | [diff] [blame] | 30 | public class SimpleFabricCommandCompleter extends AbstractChoicesCompleter { |
| 31 | |
Ray Milkey | 10f35dc | 2018-02-01 09:26:51 -0800 | [diff] [blame] | 32 | private static final List<String> COMMAND_LIST = |
Lee Yongjae | 6dc7e4f | 2017-12-06 16:17:51 +0900 | [diff] [blame] | 33 | Arrays.asList("show", "intents", "reactive-intents", "refresh", "flush"); |
| 34 | |
| 35 | @Override |
| 36 | public List<String> choices() { |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 37 | if (commandLine.getArguments() == null) { |
Lee Yongjae | 6dc7e4f | 2017-12-06 16:17:51 +0900 | [diff] [blame] | 38 | return Collections.emptyList(); |
| 39 | } |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 40 | List<String> argList = Lists.newArrayList(commandLine.getArguments()); |
Lee Yongjae | 6dc7e4f | 2017-12-06 16:17:51 +0900 | [diff] [blame] | 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 | |