-
Notifications
You must be signed in to change notification settings - Fork 11
/
root.go
72 lines (54 loc) · 1.92 KB
/
root.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
// Package cmd - 어플리케이션 실행을 위한 Cobra 기반의 CLI Commands 기능 제공
package cmd
import (
"os"
"github.com/cloud-barista/cb-ladybug/src/grpc-api/cbadm/app"
"github.com/spf13/cobra"
)
// ===== [ Constants and Variables ] =====
const (
// CLIVersion - cbadm cli 버전
CLIVersion = "1.0"
)
var (
clusterName string
)
type CbadmOptions struct {
app.Options
}
// ===== [ Types ] =====
// ===== [ Implementations ] =====
// ===== [ Private Functions ] =====
// ===== [ Public Functions ] =====
// NewRootCmd - 어플리케이션 진입점으로 사용할 Root Cobra Command 생성
func NewRootCmd() *cobra.Command {
o := CbadmOptions{
Options: app.Options{
OutStream: os.Stdout,
},
}
rootCmd := &cobra.Command{
Use: "cbadm",
Short: "cbadm is a lightweight grpc cli tool",
Long: "This is a lightweight grpc cli tool for Cloud-Barista",
}
// 옵션 플래그 설정
rootCmd.PersistentFlags().StringVar(&o.Name, "name", "", "name")
rootCmd.PersistentFlags().StringVarP(&o.ConfigFile, "config", "c", "", "configuration file path")
rootCmd.PersistentFlags().StringVarP(&o.Namespace, "namespace", "n", "", "cloud-baristar namespace")
rootCmd.PersistentFlags().StringVarP(&o.Filename, "file", "f", "", "filepath")
rootCmd.PersistentFlags().StringVarP(&o.Data, "data", "d", "", "input string data")
rootCmd.PersistentFlags().StringVarP(&o.Output, "output", "o", "yaml", "output format (json/yaml)")
if err := app.OnConfigInitialize(o.ConfigFile); err != nil {
o.PrintlnError(err)
os.Exit(1)
}
// Adds the commands for application.
rootCmd.AddCommand(NewCommandConfig(&o.Options))
rootCmd.AddCommand(NewVersionCmd())
rootCmd.AddCommand(NewHealthyCmd(&o.Options))
rootCmd.AddCommand(NewGetCmd(&o.Options))
rootCmd.AddCommand(NewCreateCmd(&o.Options))
rootCmd.AddCommand(NewDeleteCmd(&o.Options))
return rootCmd
}