/
config.go
48 lines (41 loc) · 919 Bytes
/
config.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
package cmd
import (
"encoding/json"
"fmt"
"github.com/cedana/cedana/utils"
"github.com/spf13/cobra"
)
var configCmd = &cobra.Command{
Use: "config",
Short: "manage configuration",
}
var showCmd = &cobra.Command{
Use: "show",
Short: "show currently set configuration",
RunE: func(cmd *cobra.Command, args []string) error {
cfg, err := utils.InitConfig()
if err != nil {
return err
}
prettycfg, err := json.MarshalIndent(cfg, "", " ")
if err != nil {
return err
}
fmt.Printf("config: %v\n", string(prettycfg))
return nil
},
}
var generateCmd = &cobra.Command{
Use: "generate",
Short: "generate configuration",
RunE: func(cmd *cobra.Command, args []string) error {
cfg := utils.GenSampleConfig()
fmt.Printf("config: %v\n", string(cfg))
return nil
},
}
func init() {
rootCmd.AddCommand(configCmd)
configCmd.AddCommand(showCmd)
configCmd.AddCommand(generateCmd)
}