-
Notifications
You must be signed in to change notification settings - Fork 11
/
get.go
68 lines (60 loc) · 1.67 KB
/
get.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
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"github.com/cloud-barista/cb-ladybug/src/grpc-api/cbadm/app"
"github.com/cloud-barista/cb-ladybug/src/utils/lang"
)
func NewGetCmd(o *app.Options) *cobra.Command {
fnValidate := func() error {
o.Namespace = lang.NVL(o.Namespace, app.Config.GetCurrentContext().Namespace)
if o.Namespace == "" {
return fmt.Errorf("Namespace is required.")
}
return nil
}
getCmd := &cobra.Command{
Use: "get",
Short: "Get command",
Long: "This is a get command",
}
getCmd.AddCommand(&cobra.Command{
Use: "cluster (NAME | --name NAME) [options]",
Short: "Get cluster or cluster list",
Long: "This is a get command for cluster",
Args: app.BindCommandArgs(&o.Name),
Run: func(cmd *cobra.Command, args []string) {
app.ValidateError(cmd, fnValidate())
SetupAndRun(cmd, o)
},
})
cmdNode := &cobra.Command{
Use: "node (NAME | --name NAME) [options]",
Short: "Get node or node list",
Long: "This is a get command for node",
Args: app.BindCommandArgs(&o.Name),
Run: func(cmd *cobra.Command, args []string) {
app.ValidateError(cmd, fnValidate())
app.ValidateError(cmd, func() error {
if clusterName == "" {
return fmt.Errorf("cluster name is required")
}
return nil
}())
SetupAndRun(cmd, o)
},
}
cmdNode.Flags().StringVar(&clusterName, "cluster", "", "Name of cluster")
getCmd.AddCommand(cmdNode)
/*
getCmd.AddCommand(&cobra.Command{
Use: "credential (NAME | --name NAME) [options]",
Short: "Get credential",
Long: "This is get command for credential",
Run: func(cmd *cobra.Command, args []string) {
SetupAndRun(cmd, o)
},
})
*/
return getCmd
}