From 5c52e37b37fbc6fff354c53e8863527e2073115d Mon Sep 17 00:00:00 2001 From: Michael Hindley Date: Mon, 4 Jul 2022 20:20:51 +0200 Subject: [PATCH] feat: add flag to disable namespace warning print.WarningStatusEvents is also used to report on errors that occur during command execution. First it was considered to check for the flag within print.WarningStatusEvent, but this does not seem in tune with the spirit of this flag, which is to prevent breaking output formats due to a warning that is always printed. For the context of this flag, its thus explicitly named so its clear only the namespace warning is covered, and not all warnings that are generated throughout the CLI. Names likes noWarning, disableWarning were also considered. Single char shorthand flag was also considered. --- cmd/components.go | 5 ++++- cmd/configurations.go | 5 ++++- cmd/init.go | 27 ++++++++++++++------------- cmd/list.go | 6 +++++- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/cmd/components.go b/cmd/components.go index b2537ee96..5b74926b0 100644 --- a/cmd/components.go +++ b/cmd/components.go @@ -34,7 +34,9 @@ var ComponentsCmd = &cobra.Command{ Short: "List all Dapr components. Supported platforms: Kubernetes", Run: func(cmd *cobra.Command, args []string) { if kubernetesMode { - print.WarningStatusEvent(os.Stdout, "In future releases, this command will only query the \"default\" namespace by default. Please use the --namespace flag for a specific namespace, or the --all-namespaces (-A) flag for all namespaces.") + if !noNamespaceWarning { + print.WarningStatusEvent(os.Stdout, "In future releases, this command will only query the \"default\" namespace by default. Please use the --namespace flag for a specific namespace, or the --all-namespaces (-A) flag for all namespaces.") + } if allNamespaces { resourceNamespace = meta_v1.NamespaceAll } else if resourceNamespace == "" { @@ -67,6 +69,7 @@ dapr components -k --all-namespaces func init() { ComponentsCmd.Flags().BoolVarP(&allNamespaces, "all-namespaces", "A", false, "If true, list all Dapr components in all namespaces") + ComponentsCmd.Flags().BoolVar(&noNamespaceWarning, "no-namespace-warning", false, "Disable upcoming namespace warnings in command output") ComponentsCmd.Flags().StringVarP(&componentsName, "name", "n", "", "The components name to be printed (optional)") ComponentsCmd.Flags().StringVarP(&resourceNamespace, "namespace", "", "", "List all namespace components in a Kubernetes cluster") ComponentsCmd.Flags().StringVarP(&componentsOutputFormat, "output", "o", "list", "Output format (options: json or yaml or list)") diff --git a/cmd/configurations.go b/cmd/configurations.go index ef73c3aef..1d23a4d5f 100644 --- a/cmd/configurations.go +++ b/cmd/configurations.go @@ -34,7 +34,9 @@ var ConfigurationsCmd = &cobra.Command{ Short: "List all Dapr configurations. Supported platforms: Kubernetes", Run: func(cmd *cobra.Command, args []string) { if kubernetesMode { - print.WarningStatusEvent(os.Stdout, "In future releases, this command will only query the \"default\" namespace by default. Please use the --namespace flag for a specific namespace, or the --all-namespaces (-A) flag for all namespaces.") + if !noNamespaceWarning { + print.WarningStatusEvent(os.Stdout, "In future releases, this command will only query the \"default\" namespace by default. Please use the --namespace flag for a specific namespace, or the --all-namespaces (-A) flag for all namespaces.") + } if allNamespaces { resourceNamespace = meta_v1.NamespaceAll } else if resourceNamespace == "" { @@ -67,6 +69,7 @@ dapr configurations -k --all-namespaces func init() { ConfigurationsCmd.Flags().BoolVarP(&allNamespaces, "all-namespaces", "A", false, "If true, list all Dapr configurations in all namespaces") + ConfigurationsCmd.Flags().BoolVar(&noNamespaceWarning, "no-namespace-warning", false, "Disable upcoming namespace warnings in command output") ConfigurationsCmd.Flags().StringVarP(&configurationName, "name", "n", "", "The configuration name to be printed (optional)") ConfigurationsCmd.Flags().StringVarP(&resourceNamespace, "namespace", "", "", "List Define namespace configurations in a Kubernetes cluster") ConfigurationsCmd.Flags().StringVarP(&configurationOutputFormat, "output", "o", "list", "Output format (options: json or yaml or list)") diff --git a/cmd/init.go b/cmd/init.go index 1d19f1d1b..18858db33 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -27,19 +27,20 @@ import ( ) var ( - kubernetesMode bool - wait bool - timeout uint - slimMode bool - runtimeVersion string - dashboardVersion string - allNamespaces bool - initNamespace string - resourceNamespace string - enableMTLS bool - enableHA bool - values []string - fromDir string + kubernetesMode bool + wait bool + timeout uint + slimMode bool + runtimeVersion string + dashboardVersion string + allNamespaces bool + initNamespace string + resourceNamespace string + enableMTLS bool + enableHA bool + values []string + fromDir string + noNamespaceWarning bool ) var InitCmd = &cobra.Command{ diff --git a/cmd/list.go b/cmd/list.go index 1d7a6047c..f1b931a6c 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -78,7 +78,10 @@ dapr list -k --all-namespaces }, Run: func(cmd *cobra.Command, args []string) { if kubernetesMode { - print.WarningStatusEvent(os.Stdout, "In future releases, this command will only query the \"default\" namespace by default. Please use the --namespace flag for a specific namespace, or the --all-namespaces (-A) flag for all namespaces.") + if !noNamespaceWarning { + print.WarningStatusEvent(os.Stdout, "In future releases, this command will only query the \"default\" namespace by default. Please use the --namespace flag for a specific namespace, or the --all-namespaces (-A) flag for all namespaces.") + } + if allNamespaces { resourceNamespace = meta_v1.NamespaceAll } else if resourceNamespace == "" { @@ -112,6 +115,7 @@ dapr list -k --all-namespaces func init() { ListCmd.Flags().BoolVarP(&allNamespaces, "all-namespaces", "A", false, "If true, list all Dapr pods in all namespaces") ListCmd.Flags().BoolVarP(&kubernetesMode, "kubernetes", "k", false, "List all Dapr pods in a Kubernetes cluster") + ListCmd.Flags().BoolVar(&noNamespaceWarning, "no-namespace-warning", false, "Disable upcoming namespace warnings in command output") ListCmd.Flags().StringVarP(&resourceNamespace, "namespace", "", "", "List define namespace pod in a Kubernetes cluster") ListCmd.Flags().StringVarP(&outputFormat, "output", "o", "", "The output format of the list. Valid values are: json, yaml, or table (default)") ListCmd.Flags().BoolP("help", "h", false, "Print this help message")