From 0648f5604951bca32e58477f3cb56f6136e1b805 Mon Sep 17 00:00:00 2001 From: Max Jonas Werner Date: Mon, 30 Jan 2023 16:19:10 +0100 Subject: [PATCH] fix misleading messaging when using `-A` flag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before: ``` $ flux get source git -A ✗ no GitRepository objects found in flux-system namespace ``` After: ``` $ flux get source git -A ✗ no GitRepository objects found in any namespace ``` Signed-off-by: Max Jonas Werner --- cmd/flux/get.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/cmd/flux/get.go b/cmd/flux/get.go index 2236e36e77..6723fb22f8 100644 --- a/cmd/flux/get.go +++ b/cmd/flux/get.go @@ -163,9 +163,16 @@ func (get getCommand) run(cmd *cobra.Command, args []string) error { if get.list.len() == 0 { if len(args) > 0 { - logger.Failuref("%s object '%s' not found in '%s' namespace", get.kind, args[0], *kubeconfigArgs.Namespace) + logger.Failuref("%s object '%s' not found in %s namespace", + get.kind, + args[0], + namespaceNameOrAny(getArgs.allNamespaces, *kubeconfigArgs.Namespace), + ) } else if !getAll { - logger.Failuref("no %s objects found in %s namespace", get.kind, *kubeconfigArgs.Namespace) + logger.Failuref("no %s objects found in %s namespace", + get.kind, + namespaceNameOrAny(getArgs.allNamespaces, *kubeconfigArgs.Namespace), + ) } return nil } @@ -192,6 +199,13 @@ func (get getCommand) run(cmd *cobra.Command, args []string) error { return nil } +func namespaceNameOrAny(allNamespaces bool, namespaceName string) string { + if allNamespaces { + return "any" + } + return fmt.Sprintf("%q", namespaceName) +} + func getRowsToPrint(getAll bool, list summarisable) ([][]string, error) { noFilter := true var conditionType, conditionStatus string