-
Notifications
You must be signed in to change notification settings - Fork 2
/
connection.go
133 lines (103 loc) · 3.82 KB
/
connection.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// gRPC Runtime of CB-Spider.
// The CB-Spider is a sub-Framework of the Cloud-Barista Multi-Cloud Project.
// The CB-Spider Mission is to connect all the clouds with a single interface.
//
// * Cloud-Barista: https://github.com/cloud-barista
//
// by CB-Spider Team, 2020.09.
package cmd
import (
"github.com/spf13/cobra"
"github.com/cloud-barista/poc-cicd-spider/api-runtime/grpc-runtime/logger"
)
// ===== [ Constants and Variables ] =====
// ===== [ Types ] =====
// ===== [ Implementations ] =====
// ===== [ Private Functions ] =====
// ===== [ Public Functions ] =====
// NewConnectionCmd - Connection Config 관리 기능을 수행하는 Cobra Command 생성
func NewConnectionCmd() *cobra.Command {
connectionCmd := &cobra.Command{
Use: "connection",
Short: "This is a manageable command for connection config",
Long: "This is a manageable command for connection config",
}
// Adds the commands for application.
connectionCmd.AddCommand(NewConnectionCreateCmd())
connectionCmd.AddCommand(NewConnectionListCmd())
connectionCmd.AddCommand(NewConnectionGetCmd())
connectionCmd.AddCommand(NewConnectionDeleteCmd())
return connectionCmd
}
// NewConnectionCreateCmd - Connection Config 생성 기능을 수행하는 Cobra Command 생성
func NewConnectionCreateCmd() *cobra.Command {
createCmd := &cobra.Command{
Use: "create",
Short: "This is create command for connection config",
Long: "This is create command for connection config",
Run: func(cmd *cobra.Command, args []string) {
logger := logger.NewLogger()
readInDataFromFile()
if inData == "" {
logger.Error("failed to validate --indata parameter")
return
}
logger.Debug("--indata parameter value : \n", inData)
logger.Debug("--infile parameter value : ", inFile)
SetupAndRun(cmd, args)
},
}
createCmd.PersistentFlags().StringVarP(&inData, "indata", "d", "", "input string data")
createCmd.PersistentFlags().StringVarP(&inFile, "infile", "f", "", "input file path")
return createCmd
}
// NewConnectionListCmd - Connection Config 목록 기능을 수행하는 Cobra Command 생성
func NewConnectionListCmd() *cobra.Command {
listCmd := &cobra.Command{
Use: "list",
Short: "This is list command for connection config",
Long: "This is list command for connection config",
Run: func(cmd *cobra.Command, args []string) {
SetupAndRun(cmd, args)
},
}
return listCmd
}
// NewConnectionGetCmd - Connection Config 조회 기능을 수행하는 Cobra Command 생성
func NewConnectionGetCmd() *cobra.Command {
getCmd := &cobra.Command{
Use: "get",
Short: "This is get command for connection config",
Long: "This is get command for connection config",
Run: func(cmd *cobra.Command, args []string) {
logger := logger.NewLogger()
if configName == "" {
logger.Error("failed to validate --name parameter")
return
}
logger.Debug("--name parameter value : ", configName)
SetupAndRun(cmd, args)
},
}
getCmd.PersistentFlags().StringVarP(&configName, "name", "n", "", "config name")
return getCmd
}
// NewConnectionDeleteCmd - Connection Config 삭제 기능을 수행하는 Cobra Command 생성
func NewConnectionDeleteCmd() *cobra.Command {
deleteCmd := &cobra.Command{
Use: "delete",
Short: "This is delete command for connection config",
Long: "This is delete command for connection config",
Run: func(cmd *cobra.Command, args []string) {
logger := logger.NewLogger()
if configName == "" {
logger.Error("failed to validate --name parameter")
return
}
logger.Debug("--name parameter value : ", configName)
SetupAndRun(cmd, args)
},
}
deleteCmd.PersistentFlags().StringVarP(&configName, "name", "n", "", "config name")
return deleteCmd
}