Scott Baker | 5281d00 | 2019-05-16 10:45:26 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Portions copyright 2019-present Open Networking Foundation |
| 3 | * Original copyright 2019-present Ciena Corporation |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | package commands |
| 18 | |
| 19 | import ( |
| 20 | flags "github.com/jessevdk/go-flags" |
| 21 | "sort" |
| 22 | ) |
| 23 | |
| 24 | const ( |
| 25 | DEFAULT_MODELTYPE_LIST_FORMAT = "{{ . }}" |
| 26 | ) |
| 27 | |
| 28 | type ModelTypeList struct { |
| 29 | OutputOptions |
| 30 | } |
| 31 | |
| 32 | type ModelTypeOpts struct { |
| 33 | List ModelTypeList `command:"list"` |
| 34 | } |
| 35 | |
| 36 | var modelTypeOpts = ModelTypeOpts{} |
| 37 | |
| 38 | func RegisterModelTypeCommands(parser *flags.Parser) { |
| 39 | parser.AddCommand("modeltype", "model type commands", "Commands to query the types of models", &modelTypeOpts) |
| 40 | } |
| 41 | |
| 42 | func (options *ModelTypeList) Execute(args []string) error { |
| 43 | conn, descriptor, err := InitReflectionClient() |
| 44 | if err != nil { |
| 45 | return err |
| 46 | } |
| 47 | |
| 48 | defer conn.Close() |
| 49 | |
| 50 | models, err := GetModelNames(descriptor) |
| 51 | if err != nil { |
| 52 | return err |
| 53 | } |
| 54 | |
| 55 | model_names := []string{} |
| 56 | for k := range models { |
| 57 | model_names = append(model_names, k) |
| 58 | } |
| 59 | |
| 60 | sort.Strings(model_names) |
| 61 | |
Scott Baker | 175cb40 | 2019-05-17 16:13:06 -0700 | [diff] [blame] | 62 | FormatAndGenerateOutput( |
| 63 | &options.OutputOptions, |
| 64 | DEFAULT_MODELTYPE_LIST_FORMAT, |
| 65 | DEFAULT_MODELTYPE_LIST_FORMAT, |
| 66 | model_names) |
Scott Baker | 5281d00 | 2019-05-16 10:45:26 -0700 | [diff] [blame] | 67 | |
| 68 | return nil |
| 69 | } |