blob: be2294ceff80d566c863ad6695a4fcfd8ba9a3ac [file] [log] [blame]
Scott Baker5281d002019-05-16 10:45:26 -07001/*
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 */
17package commands
18
19import (
20 flags "github.com/jessevdk/go-flags"
21 "sort"
22)
23
24const (
25 DEFAULT_MODELTYPE_LIST_FORMAT = "{{ . }}"
26)
27
28type ModelTypeList struct {
29 OutputOptions
30}
31
32type ModelTypeOpts struct {
33 List ModelTypeList `command:"list"`
34}
35
36var modelTypeOpts = ModelTypeOpts{}
37
38func RegisterModelTypeCommands(parser *flags.Parser) {
39 parser.AddCommand("modeltype", "model type commands", "Commands to query the types of models", &modelTypeOpts)
40}
41
42func (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
62 FormatAndGenerateOutput(&options.OutputOptions, DEFAULT_MODELTYPE_LIST_FORMAT, "", model_names)
63
64 return nil
65}