github.com/argoproj/argo-cd/v3@v3.2.1/cmd/argocd/commands/root.go (about) 1 package commands 2 3 import ( 4 "fmt" 5 6 "github.com/argoproj/argo-cd/v3/util/cache" 7 8 "github.com/spf13/cobra" 9 "k8s.io/client-go/tools/clientcmd" 10 11 "github.com/argoproj/argo-cd/v3/cmd/argocd/commands/admin" 12 "github.com/argoproj/argo-cd/v3/cmd/argocd/commands/initialize" 13 cmdutil "github.com/argoproj/argo-cd/v3/cmd/util" 14 "github.com/argoproj/argo-cd/v3/common" 15 argocdclient "github.com/argoproj/argo-cd/v3/pkg/apiclient" 16 "github.com/argoproj/argo-cd/v3/util/cli" 17 "github.com/argoproj/argo-cd/v3/util/config" 18 "github.com/argoproj/argo-cd/v3/util/env" 19 "github.com/argoproj/argo-cd/v3/util/errors" 20 "github.com/argoproj/argo-cd/v3/util/localconfig" 21 ) 22 23 func init() { 24 cobra.OnInitialize(initConfig) 25 } 26 27 func initConfig() { 28 cli.SetLogFormat(cmdutil.LogFormat) 29 cli.SetLogLevel(cmdutil.LogLevel) 30 } 31 32 // NewCommand returns a new instance of an argocd command 33 func NewCommand() *cobra.Command { 34 var ( 35 clientOpts argocdclient.ClientOptions 36 pathOpts = clientcmd.NewDefaultPathOptions() 37 ) 38 39 command := &cobra.Command{ 40 Use: cliName, 41 Short: "argocd controls a Argo CD server", 42 Run: func(c *cobra.Command, args []string) { 43 c.HelpFunc()(c, args) 44 }, 45 DisableAutoGenTag: true, 46 SilenceUsage: true, 47 } 48 49 command.AddCommand(NewCompletionCommand()) 50 command.AddCommand(initialize.InitCommand(NewVersionCmd(&clientOpts, nil))) 51 command.AddCommand(initialize.InitCommand(NewClusterCommand(&clientOpts, pathOpts))) 52 command.AddCommand(initialize.InitCommand(NewApplicationCommand(&clientOpts))) 53 command.AddCommand(initialize.InitCommand(NewAppSetCommand(&clientOpts))) 54 command.AddCommand(NewLoginCommand(&clientOpts)) 55 command.AddCommand(NewReloginCommand(&clientOpts)) 56 command.AddCommand(initialize.InitCommand(NewRepoCommand(&clientOpts))) 57 command.AddCommand(initialize.InitCommand(NewRepoCredsCommand(&clientOpts))) 58 command.AddCommand(NewContextCommand(&clientOpts)) 59 command.AddCommand(initialize.InitCommand(NewProjectCommand(&clientOpts))) 60 command.AddCommand(initialize.InitCommand(NewAccountCommand(&clientOpts))) 61 command.AddCommand(NewLogoutCommand(&clientOpts)) 62 command.AddCommand(initialize.InitCommand(NewCertCommand(&clientOpts))) 63 command.AddCommand(initialize.InitCommand(NewGPGCommand(&clientOpts))) 64 command.AddCommand(admin.NewAdminCommand(&clientOpts)) 65 command.AddCommand(initialize.InitCommand(NewConfigureCommand(&clientOpts))) 66 67 defaultLocalConfigPath, err := localconfig.DefaultLocalConfigPath() 68 errors.CheckError(err) 69 command.PersistentFlags().StringVar(&clientOpts.ConfigPath, "config", config.GetFlag("config", defaultLocalConfigPath), "Path to Argo CD config") 70 command.PersistentFlags().StringVar(&clientOpts.ServerAddr, "server", config.GetFlag("server", env.StringFromEnv(common.EnvServer, "")), "Argo CD server address") 71 command.PersistentFlags().BoolVar(&clientOpts.PlainText, "plaintext", config.GetBoolFlag("plaintext"), "Disable TLS") 72 command.PersistentFlags().BoolVar(&clientOpts.Insecure, "insecure", config.GetBoolFlag("insecure"), "Skip server certificate and domain verification") 73 command.PersistentFlags().StringVar(&clientOpts.CertFile, "server-crt", config.GetFlag("server-crt", ""), "Server certificate file") 74 command.PersistentFlags().StringVar(&clientOpts.ClientCertFile, "client-crt", config.GetFlag("client-crt", ""), "Client certificate file") 75 command.PersistentFlags().StringVar(&clientOpts.ClientCertKeyFile, "client-crt-key", config.GetFlag("client-crt-key", ""), "Client certificate key file") 76 command.PersistentFlags().StringVar(&clientOpts.AuthToken, "auth-token", config.GetFlag("auth-token", env.StringFromEnv(common.EnvAuthToken, "")), fmt.Sprintf("Authentication token; set this or the %s environment variable", common.EnvAuthToken)) 77 command.PersistentFlags().BoolVar(&clientOpts.GRPCWeb, "grpc-web", config.GetBoolFlag("grpc-web"), "Enables gRPC-web protocol. Useful if Argo CD server is behind proxy which does not support HTTP2.") 78 command.PersistentFlags().StringVar(&clientOpts.GRPCWebRootPath, "grpc-web-root-path", config.GetFlag("grpc-web-root-path", ""), "Enables gRPC-web protocol. Useful if Argo CD server is behind proxy which does not support HTTP2. Set web root.") 79 command.PersistentFlags().StringVar(&cmdutil.LogFormat, "logformat", config.GetFlag("logformat", "json"), "Set the logging format. One of: json|text") 80 command.PersistentFlags().StringVar(&cmdutil.LogLevel, "loglevel", config.GetFlag("loglevel", "info"), "Set the logging level. One of: debug|info|warn|error") 81 command.PersistentFlags().StringSliceVarP(&clientOpts.Headers, "header", "H", config.GetStringSliceFlag("header", []string{}), "Sets additional header to all requests made by Argo CD CLI. (Can be repeated multiple times to add multiple headers, also supports comma separated headers)") 82 command.PersistentFlags().BoolVar(&clientOpts.PortForward, "port-forward", config.GetBoolFlag("port-forward"), "Connect to a random argocd-server port using port forwarding") 83 command.PersistentFlags().StringVar(&clientOpts.PortForwardNamespace, "port-forward-namespace", config.GetFlag("port-forward-namespace", ""), "Namespace name which should be used for port forwarding") 84 command.PersistentFlags().IntVar(&clientOpts.HttpRetryMax, "http-retry-max", config.GetIntFlag("http-retry-max", 0), "Maximum number of retries to establish http connection to Argo CD server") 85 command.PersistentFlags().BoolVar(&clientOpts.Core, "core", config.GetBoolFlag("core"), "If set to true then CLI talks directly to Kubernetes instead of talking to Argo CD API server") 86 command.PersistentFlags().StringVar(&clientOpts.Context, "argocd-context", "", "The name of the Argo-CD server context to use") 87 command.PersistentFlags().StringVar(&clientOpts.ServerName, "server-name", env.StringFromEnv(common.EnvServerName, common.DefaultServerName), fmt.Sprintf("Name of the Argo CD API server; set this or the %s environment variable when the server's name label differs from the default, for example when installing via the Helm chart", common.EnvServerName)) 88 command.PersistentFlags().StringVar(&clientOpts.AppControllerName, "controller-name", env.StringFromEnv(common.EnvAppControllerName, common.DefaultApplicationControllerName), fmt.Sprintf("Name of the Argo CD Application controller; set this or the %s environment variable when the controller's name label differs from the default, for example when installing via the Helm chart", common.EnvAppControllerName)) 89 command.PersistentFlags().StringVar(&clientOpts.RedisHaProxyName, "redis-haproxy-name", env.StringFromEnv(common.EnvRedisHaProxyName, common.DefaultRedisHaProxyName), fmt.Sprintf("Name of the Redis HA Proxy; set this or the %s environment variable when the HA Proxy's name label differs from the default, for example when installing via the Helm chart", common.EnvRedisHaProxyName)) 90 command.PersistentFlags().StringVar(&clientOpts.RedisName, "redis-name", env.StringFromEnv(common.EnvRedisName, common.DefaultRedisName), fmt.Sprintf("Name of the Redis deployment; set this or the %s environment variable when the Redis's name label differs from the default, for example when installing via the Helm chart", common.EnvRedisName)) 91 command.PersistentFlags().StringVar(&clientOpts.RepoServerName, "repo-server-name", env.StringFromEnv(common.EnvRepoServerName, common.DefaultRepoServerName), fmt.Sprintf("Name of the Argo CD Repo server; set this or the %s environment variable when the server's name label differs from the default, for example when installing via the Helm chart", common.EnvRepoServerName)) 92 command.PersistentFlags().StringVar(&clientOpts.RedisCompression, "redis-compress", env.StringFromEnv("REDIS_COMPRESSION", string(cache.RedisCompressionGZip)), "Enable this if the application controller is configured with redis compression enabled. (possible values: gzip, none)") 93 command.PersistentFlags().BoolVar(&clientOpts.PromptsEnabled, "prompts-enabled", localconfig.GetPromptsEnabled(true), "Force optional interactive prompts to be enabled or disabled, overriding local configuration. If not specified, the local configuration value will be used, which is false by default.") 94 95 clientOpts.KubeOverrides = &clientcmd.ConfigOverrides{} 96 command.PersistentFlags().StringVar(&clientOpts.KubeOverrides.CurrentContext, "kube-context", "", "Directs the command to the given kube-context") 97 98 return command 99 }