This repository has been archived by the owner on Oct 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
describe_cmd.go
79 lines (68 loc) · 2.01 KB
/
describe_cmd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
package bindingtemplate
import (
"fmt"
"github.com/Azure/service-catalog-templates/cmd/svcatt/command"
"github.com/Azure/service-catalog-templates/cmd/svcatt/output"
"github.com/kubernetes-incubator/service-catalog/cmd/svcat/command"
"github.com/spf13/cobra"
)
type describeCmd struct {
*svcattcommand.Context
ns string
name string
traverse bool
brokerLevel bool
clusterLevel bool
serviceType string
}
// NewDescribeCmd builds a "svcat describe binding-template" command
func NewDescribeCmd(cxt *svcattcommand.Context) *cobra.Command {
describeCmd := &describeCmd{Context: cxt}
cmd := &cobra.Command{
Use: "binding-template NAME",
Aliases: []string{"binding-template", "bindingtemplates", "bindingtemplate", "bndt"},
Short: "Show details of a specific binding template",
Example: `
svcat describe binding-template default-mysqldb
`,
PreRunE: command.PreRunE(describeCmd),
RunE: command.RunE(describeCmd),
}
cmd.Flags().StringVarP(
&describeCmd.ns,
"namespace",
"n",
"",
"The namespace in which to get the resource",
)
cmd.Flags().BoolVarP(&describeCmd.brokerLevel, "broker", "b", false,
"List templates defined at the broker-level")
cmd.Flags().BoolVarP(&describeCmd.clusterLevel, "cluster", "c", false,
"List templates defined at the cluster-level")
cmd.Flags().StringVarP(&describeCmd.serviceType, "type", "t", "",
"Filter the templates by a service type")
return cmd
}
func (c *describeCmd) Validate(args []string) error {
if len(args) == 0 {
return fmt.Errorf("name is required")
}
c.name = args[0]
if c.ns == "" {
c.ns = c.App().CurrentNamespace
}
return nil
}
func (c *describeCmd) Run() error {
return c.describe()
}
func (c *describeCmd) describe() error {
bndt, err := c.App().GetBindingTemplate(c.ns, c.clusterLevel, c.brokerLevel, c.name)
if err != nil {
return err
}
svcattoutput.WriteBindingTemplateDetails(c.Output, bndt)
return nil
}