Skip to content

Commit

Permalink
Adds debug flag (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
cveticm authored Feb 13, 2025
1 parent 528a423 commit 59d53c7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
17 changes: 16 additions & 1 deletion internal/cli/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
2 changes: 2 additions & 0 deletions internal/flag/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions internal/usage/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down

0 comments on commit 59d53c7

Please sign in to comment.