diff --git a/internal/cli/kubernetes/kubernetes.go b/internal/cli/kubernetes/kubernetes.go index febe9c3..99099fb 100644 --- a/internal/cli/kubernetes/kubernetes.go +++ b/internal/cli/kubernetes/kubernetes.go @@ -20,18 +20,29 @@ import ( coreConfig "github.com/mongodb/atlas-cli-core/config" "github.com/mongodb/atlas-cli-plugin-kubernetes/internal/cli/kubernetes/config" "github.com/mongodb/atlas-cli-plugin-kubernetes/internal/cli/kubernetes/operator" + "github.com/mongodb/atlas-cli-plugin-kubernetes/internal/flag" + cliLog "github.com/mongodb/atlas-cli-plugin-kubernetes/internal/log" + "github.com/mongodb/atlas-cli-plugin-kubernetes/internal/usage" "github.com/spf13/cobra" ) func Builder() *cobra.Command { const use = "kubernetes" + var ( + debugLevel bool + ) cmd := &cobra.Command{ Use: use, Short: "Manage Kubernetes resources.", Long: `This command provides access to Kubernetes features within Atlas.`, - PersistentPreRun: func(_ *cobra.Command, _ []string) { + PersistentPreRun: func(cmd *cobra.Command, _ []string) { + cliLog.SetWriter(cmd.ErrOrStderr()) + if debugLevel { + cliLog.SetLevel(cliLog.DebugLevel) + } + err := coreConfig.LoadAtlasCLIConfig() if err != nil { log.Fatalf("Failed to load Atlas CLI config: %v", err) @@ -40,5 +51,9 @@ func Builder() *cobra.Command { } cmd.AddCommand(config.Builder(), operator.Builder()) + + cmd.PersistentFlags().BoolVarP(&debugLevel, flag.Debug, flag.DebugShort, false, usage.Debug) + _ = cmd.PersistentFlags().MarkHidden(flag.Debug) + return cmd } diff --git a/internal/flag/flags.go b/internal/flag/flags.go index d6eda6f..12a1b73 100644 --- a/internal/flag/flags.go +++ b/internal/flag/flags.go @@ -18,6 +18,8 @@ const ( OrgID = "orgId" // OrgID flag to use an Organization ID ProjectID = "projectId" // ProjectID flag to use a project ID ClusterName = "clusterName" // ClusterName flag + Debug = "debug" // Debug flag to set debug log level + DebugShort = "D" // DebugShort flag to set debug log level OperatorIncludeSecrets = "includeSecrets" // OperatorIncludeSecrets flag OperatorTargetNamespace = "targetNamespace" // OperatorTargetNamespace flag OperatorWatchNamespace = "watchNamespace" // OperatorTargetNamespace flag diff --git a/internal/usage/usage.go b/internal/usage/usage.go index bf25018..b9b6082 100644 --- a/internal/usage/usage.go +++ b/internal/usage/usage.go @@ -18,6 +18,7 @@ const ( ProjectID = "Hexadecimal string that identifies the project to use. This option overrides the settings in the configuration file or environment variable." OrgID = "Organization ID to use. This option overrides the settings in the configuration file or environment variable." ExporterClusterName = "One or more comma separated cluster names to import" + Debug = "Debug log level." OperatorIncludeSecrets = "Flag that generates kubernetes secrets with data for projects, users, deployments entities." OperatorTargetNamespace = "Namespaces to use for generated kubernetes entities" OperatorVersion = "Version of Atlas Kubernetes Operator to generate resources for."