-
Notifications
You must be signed in to change notification settings - Fork 2
/
flag.go
43 lines (36 loc) · 1.42 KB
/
flag.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
package bootstrap
import (
"os"
"github.com/giantswarm/microerror"
"github.com/spf13/cobra"
)
const (
githubToken = "github-token"
installOperators = "install-operators"
kubeconfig = "kubeconfig"
kubeconfigEnvVar = "KUBECONFIG"
kubeconfigPath = "kubeconfig-path"
wait = "wait"
)
type flag struct {
GithubToken string
InstallOperators bool
KubeConfig string
KubeConfigPath string
Wait bool
}
func (f *flag) Init(cmd *cobra.Command) {
cmd.Flags().StringVarP(&f.GithubToken, githubToken, "g", "", "Github Token for fetching CRDs")
cmd.Flags().BoolVarP(&f.InstallOperators, installOperators, "o", true, "Install app-operator and chart-operator")
cmd.Flags().StringVarP(&f.KubeConfig, kubeconfig, "k", "", "Explicit kubeconfig for the target cluster")
cmd.Flags().StringVarP(&f.KubeConfigPath, kubeconfigPath, "p", "", "Path to a kubeconfig file for the target cluster")
cmd.Flags().BoolVarP(&f.Wait, wait, "w", true, "Wait for all components to be ready")
}
func (f *flag) Validate() error {
if f.KubeConfig == "" && f.KubeConfigPath == "" && os.Getenv(kubeconfigEnvVar) == "" {
return microerror.Maskf(invalidFlagError, "either --%s or --%s or KUBECONFIG must be set", kubeconfig, kubeconfigPath)
} else if f.KubeConfig != "" && f.KubeConfigPath != "" {
return microerror.Maskf(invalidFlagError, "both --%s or --%s must not be set", kubeconfig, kubeconfigPath)
}
return nil
}