Skip to content

Commit 59d53c7

Browse files
authored
Adds debug flag (#35)
1 parent 528a423 commit 59d53c7

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

internal/cli/kubernetes/kubernetes.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,29 @@ import (
2020
coreConfig "github.com/mongodb/atlas-cli-core/config"
2121
"github.com/mongodb/atlas-cli-plugin-kubernetes/internal/cli/kubernetes/config"
2222
"github.com/mongodb/atlas-cli-plugin-kubernetes/internal/cli/kubernetes/operator"
23+
"github.com/mongodb/atlas-cli-plugin-kubernetes/internal/flag"
24+
cliLog "github.com/mongodb/atlas-cli-plugin-kubernetes/internal/log"
25+
"github.com/mongodb/atlas-cli-plugin-kubernetes/internal/usage"
2326

2427
"github.com/spf13/cobra"
2528
)
2629

2730
func Builder() *cobra.Command {
2831
const use = "kubernetes"
32+
var (
33+
debugLevel bool
34+
)
2935

3036
cmd := &cobra.Command{
3137
Use: use,
3238
Short: "Manage Kubernetes resources.",
3339
Long: `This command provides access to Kubernetes features within Atlas.`,
34-
PersistentPreRun: func(_ *cobra.Command, _ []string) {
40+
PersistentPreRun: func(cmd *cobra.Command, _ []string) {
41+
cliLog.SetWriter(cmd.ErrOrStderr())
42+
if debugLevel {
43+
cliLog.SetLevel(cliLog.DebugLevel)
44+
}
45+
3546
err := coreConfig.LoadAtlasCLIConfig()
3647
if err != nil {
3748
log.Fatalf("Failed to load Atlas CLI config: %v", err)
@@ -40,5 +51,9 @@ func Builder() *cobra.Command {
4051
}
4152

4253
cmd.AddCommand(config.Builder(), operator.Builder())
54+
55+
cmd.PersistentFlags().BoolVarP(&debugLevel, flag.Debug, flag.DebugShort, false, usage.Debug)
56+
_ = cmd.PersistentFlags().MarkHidden(flag.Debug)
57+
4358
return cmd
4459
}

internal/flag/flags.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const (
1818
OrgID = "orgId" // OrgID flag to use an Organization ID
1919
ProjectID = "projectId" // ProjectID flag to use a project ID
2020
ClusterName = "clusterName" // ClusterName flag
21+
Debug = "debug" // Debug flag to set debug log level
22+
DebugShort = "D" // DebugShort flag to set debug log level
2123
OperatorIncludeSecrets = "includeSecrets" // OperatorIncludeSecrets flag
2224
OperatorTargetNamespace = "targetNamespace" // OperatorTargetNamespace flag
2325
OperatorWatchNamespace = "watchNamespace" // OperatorTargetNamespace flag

internal/usage/usage.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const (
1818
ProjectID = "Hexadecimal string that identifies the project to use. This option overrides the settings in the configuration file or environment variable."
1919
OrgID = "Organization ID to use. This option overrides the settings in the configuration file or environment variable."
2020
ExporterClusterName = "One or more comma separated cluster names to import"
21+
Debug = "Debug log level."
2122
OperatorIncludeSecrets = "Flag that generates kubernetes secrets with data for projects, users, deployments entities."
2223
OperatorTargetNamespace = "Namespaces to use for generated kubernetes entities"
2324
OperatorVersion = "Version of Atlas Kubernetes Operator to generate resources for."

0 commit comments

Comments
 (0)