Luca Prete | dce16f8 | 2016-11-22 13:11:56 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Luca Prete | dce16f8 | 2016-11-22 13:11:56 -0800 | [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 | */ |
| 16 | package org.onosproject.vpls.cli.completer; |
| 17 | |
| 18 | import com.google.common.collect.Lists; |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 19 | import org.apache.karaf.shell.console.completer.ArgumentCompleter; |
Luca Prete | dce16f8 | 2016-11-22 13:11:56 -0800 | [diff] [blame] | 20 | import org.onosproject.cli.AbstractChoicesCompleter; |
| 21 | import org.onosproject.vpls.cli.VplsCommandEnum; |
| 22 | |
| 23 | import java.util.Collections; |
| 24 | import java.util.List; |
| 25 | |
| 26 | /** |
| 27 | * VPLS command completer. |
| 28 | */ |
| 29 | public class VplsCommandCompleter extends AbstractChoicesCompleter { |
| 30 | |
| 31 | @Override |
| 32 | public List<String> choices() { |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 33 | ArgumentCompleter.ArgumentList argumentList = getArgumentList(); |
| 34 | if (argumentList == null) { |
| 35 | return Collections.emptyList(); |
| 36 | } |
| 37 | List<String> argList = Lists.newArrayList(argumentList.getArguments()); |
Luca Prete | dce16f8 | 2016-11-22 13:11:56 -0800 | [diff] [blame] | 38 | String argOne = null; |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 39 | if (argList.size() > 1) { |
| 40 | argOne = argList.get(1); |
Luca Prete | dce16f8 | 2016-11-22 13:11:56 -0800 | [diff] [blame] | 41 | } |
| 42 | VplsCommandEnum vplsCommandEnum = VplsCommandEnum.enumFromString(argOne); |
| 43 | if (vplsCommandEnum != null) { |
| 44 | switch (vplsCommandEnum) { |
| 45 | case CREATE: |
Luca Prete | dce16f8 | 2016-11-22 13:11:56 -0800 | [diff] [blame] | 46 | case LIST: |
| 47 | return Collections.emptyList(); |
| 48 | default: |
| 49 | VplsCommandEnum.toStringList(); |
| 50 | } |
| 51 | } |
| 52 | return VplsCommandEnum.toStringList(); |
| 53 | } |
| 54 | } |