forked from weaveworks/weave-gitops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd.go
54 lines (42 loc) · 1.14 KB
/
cmd.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
package config
import (
"fmt"
"os"
"github.com/spf13/cobra"
cfg "github.com/weaveworks/weave-gitops/cmd/gitops/config"
"github.com/weaveworks/weave-gitops/pkg/config"
"github.com/weaveworks/weave-gitops/pkg/logger"
)
func ConfigCommand(opts *cfg.Options) *cobra.Command {
cmd := &cobra.Command{
Use: "config",
Short: "Prints out the CLI configuration for Weave GitOps",
Example: `
# Prints out the CLI configuration for Weave GitOps
gitops get config`,
SilenceUsage: true,
SilenceErrors: true,
RunE: getConfigCommandRunE(opts),
DisableAutoGenTag: true,
}
return cmd
}
func getConfigCommandRunE(opts *cfg.Options) func(*cobra.Command, []string) error {
return func(cmd *cobra.Command, args []string) error {
var err error
log := logger.NewCLILogger(os.Stdout)
gitopsConfig, err := config.GetConfig(false)
if err != nil {
log.Warningf(config.WrongConfigFormatMsg)
return err
}
log.Successf("Your CLI configuration for Weave GitOps:")
cfgStr, err := gitopsConfig.String()
if err != nil {
log.Failuref("Error printing config")
return err
}
fmt.Println(cfgStr)
return nil
}
}