-
Notifications
You must be signed in to change notification settings - Fork 5.2k
/
cmd.go
32 lines (28 loc) · 892 Bytes
/
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
package initialize
import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
flag "github.com/spf13/pflag"
"github.com/argoproj/argo-cd/v2/util/cli"
)
func RetrieveContextIfChanged(contextFlag *flag.Flag) string {
if contextFlag != nil && contextFlag.Changed {
return contextFlag.Value.String()
}
return ""
}
// InitCommand allows executing command in a headless mode: on the fly starts Argo CD API server and
// changes provided client options to use started API server port
func InitCommand(cmd *cobra.Command) *cobra.Command {
flags := pflag.NewFlagSet("tmp", pflag.ContinueOnError)
cli.AddKubectlFlagsToSet(flags)
// copy k8s persistent flags into argocd command flags
flags.VisitAll(func(flag *pflag.Flag) {
// skip Kubernetes server flags since argocd has it's own server flag
if flag.Name == "server" {
return
}
cmd.Flags().AddFlag(flag)
})
return cmd
}