-
Notifications
You must be signed in to change notification settings - Fork 11
/
delete.go
89 lines (77 loc) · 2.07 KB
/
delete.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
80
81
82
83
84
85
86
87
88
89
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"
)
// returns a cobra command
func NewDeleteCmd(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.")
}
if o.Name == "" {
return fmt.Errorf("Name is required.")
}
return nil
}
// root
cmds := &cobra.Command{
Use: "delete",
Short: "Delete command",
Long: "This is a delete command",
Run: func(c *cobra.Command, args []string) {
c.Help()
},
}
// cluster
cmds.AddCommand(&cobra.Command{
Use: "cluster (NAME | --name NAME) [options]",
Short: "Delete a cluster",
Long: "This is a delete command for cluster",
Args: app.BindCommandArgs(&o.Name),
Run: func(cmd *cobra.Command, args []string) {
app.ValidateError(cmd, fnValidate())
SetupAndRun(cmd, o)
},
})
// node
cmdNode := &cobra.Command{
Use: "node (NAME | --name NAME) --cluster CLUSTER_NAME [options]",
Short: "Delete a node",
Long: "This is a delete 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("ClusterName is required")
}
return nil
}())
SetupAndRun(cmd, o)
},
}
cmdNode.Flags().StringVar(&clusterName, "cluster", "", "Name of cluster")
cmds.AddCommand(cmdNode)
// credential
/*
cmds.AddCommand(&cobra.Command{
Use: "credential (NAME | --name NAME) [options]",
Short: "Delete a cloud credential",
Long: "This is a delete command for credential",
Args: app.BindCommandArgs(&o.Name),
Run: func(cmd *cobra.Command, args []string) {
app.ValidateError(cmd, func() error {
if o.Name == "" {
return fmt.Errorf("Name is required.")
}
return nil
}())
SetupAndRun(cmd, o)
},
})*/
return cmds
}