From db662a5a44e63b9d9946c2e0faf60c2d5097b131 Mon Sep 17 00:00:00 2001 From: Abinand P Date: Fri, 4 Oct 2024 08:55:24 +0000 Subject: [PATCH 1/2] fix: updates -the command will now print the NAMESPACE of the deployed resources Signed-off-by: Abinand P --- cyctl/internal/get/resources.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cyctl/internal/get/resources.go b/cyctl/internal/get/resources.go index 49761d1d..ffe0b4b6 100644 --- a/cyctl/internal/get/resources.go +++ b/cyctl/internal/get/resources.go @@ -40,11 +40,13 @@ func listResources(clientset *k8sclient.KubernetesClient, moduleNames []string) } headerSpacing := 20 - output := "KIND" + strings.Repeat(" ", 16) + " NAME\n" + output := "KIND" + strings.Repeat(" ", 16) + " NAME" + strings.Repeat(" ", 16) + " NAMESPACE\n" fmt.Print(output) for _, resource := range resources { nameSpacing := max(0, headerSpacing-len(resource.GetKind())) - fmt.Printf("%s"+strings.Repeat(" ", nameSpacing)+" %s\n", resource.GetKind(), resource.GetName()) + namespaceSpacing := max(0, headerSpacing-len(resource.GetName())) + fmt.Printf("%s"+strings.Repeat(" ", nameSpacing)+" %s"+strings.Repeat(" ", namespaceSpacing)+"%s\n", + resource.GetKind(), resource.GetName(), resource.GetNamespace()) } } From 98c389a6d732c28ab7a3fcdc9f16be41370e601b Mon Sep 17 00:00:00 2001 From: Abinand P Date: Sun, 6 Oct 2024 10:18:19 +0000 Subject: [PATCH 2/2] fix: swapped the name and namespace columns and also kept a distance of 2 extra spaces after the end of the length for better visibility Signed-off-by: Abinand P --- cyctl/internal/get/resources.go | 38 ++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/cyctl/internal/get/resources.go b/cyctl/internal/get/resources.go index ffe0b4b6..7eed8d53 100644 --- a/cyctl/internal/get/resources.go +++ b/cyctl/internal/get/resources.go @@ -2,7 +2,6 @@ package get import ( "fmt" - "strings" "github.com/cyclops-ui/cyclops/cyclops-ctrl/pkg/cluster/k8sclient" "github.com/cyclops-ui/cycops-cyctl/internal/kubeconfig" @@ -39,14 +38,37 @@ func listResources(clientset *k8sclient.KubernetesClient, moduleNames []string) return } - headerSpacing := 20 - output := "KIND" + strings.Repeat(" ", 16) + " NAME" + strings.Repeat(" ", 16) + " NAMESPACE\n" - fmt.Print(output) + maxKindLen := len("KIND") + maxNameLen := len("NAME") + maxNamespaceLen := len("NAMESPACE") + + for _, resource := range resources { + if len(resource.GetKind()) > maxKindLen { + maxKindLen = len(resource.GetKind()) + } + if len(resource.GetName()) > maxNameLen { + maxNameLen = len(resource.GetName()) + } + if len(resource.GetNamespace()) > maxNamespaceLen { + maxNamespaceLen = len(resource.GetNamespace()) + } + } + maxKindLen = maxKindLen + 2 + maxNameLen = maxNameLen + 2 + maxNamespaceLen = maxNamespaceLen + 2 + + // Step 2: Print the header with proper spacing + header := fmt.Sprintf("%-*s %-*s %-*s\n", + maxKindLen, "KIND", + maxNamespaceLen, "NAMESPACE", maxNameLen, "NAME") + fmt.Print(header) + + // Step 3: Print each resource with calculated spacing for _, resource := range resources { - nameSpacing := max(0, headerSpacing-len(resource.GetKind())) - namespaceSpacing := max(0, headerSpacing-len(resource.GetName())) - fmt.Printf("%s"+strings.Repeat(" ", nameSpacing)+" %s"+strings.Repeat(" ", namespaceSpacing)+"%s\n", - resource.GetKind(), resource.GetName(), resource.GetNamespace()) + fmt.Printf("%-*s %-*s %-*s\n", + maxKindLen, resource.GetKind(), + maxNamespaceLen, resource.GetNamespace(), maxNameLen, resource.GetName(), + ) } }