-
Notifications
You must be signed in to change notification settings - Fork 51
/
cmd.go
71 lines (63 loc) · 1.66 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package sync
import (
"time"
"github.com/spf13/cobra"
"github.com/openshift/openshift-azure/pkg/entrypoint/config"
)
type cmdConfig struct {
config.Common
dryRun bool
once bool
interval time.Duration
httpPort int
metricsEndpoint string
}
// NewCommand returns the cobra command for "sync".
func NewCommand() *cobra.Command {
cc := &cobra.Command{
Use: "sync",
Long: "Start sync application",
RunE: func(cmd *cobra.Command, args []string) error {
cfg, err := configFromCmd(cmd)
if err != nil {
return err
}
return start(cfg)
},
}
cc.Flags().Bool("dry-run", false, "Print resources to be synced instead of mutating cluster state.")
cc.Flags().Bool("run-once", false, "If true, run only once then quit.")
cc.Flags().Duration("interval", 3*time.Minute, "How often the sync process going to be rerun.")
cc.Flags().Int("http-port", 8080, "The http server port")
cc.Flags().String("metrics-endpoint", "/metrics", "The endpoint for serving sync metrics")
return cc
}
func configFromCmd(cmd *cobra.Command) (*cmdConfig, error) {
c := &cmdConfig{}
var err error
c.Common, err = config.CommonConfigFromCmd(cmd)
if err != nil {
return nil, err
}
c.dryRun, err = cmd.Flags().GetBool("dry-run")
if err != nil {
return nil, err
}
c.once, err = cmd.Flags().GetBool("run-once")
if err != nil {
return nil, err
}
c.interval, err = cmd.Flags().GetDuration("interval")
if err != nil {
return nil, err
}
c.httpPort, err = cmd.Flags().GetInt("http-port")
if err != nil {
return nil, err
}
c.metricsEndpoint, err = cmd.Flags().GetString("metrics-endpoint")
if err != nil {
return nil, err
}
return c, nil
}