Skip to content

Commit a56454d

Browse files
authored
🏘️ updated the displaying of the namespace (#606)
* fix: updates -the command will now print the NAMESPACE of the deployed resources Signed-off-by: Abinand P <[email protected]> * 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 <[email protected]> --------- Signed-off-by: Abinand P <[email protected]>
1 parent fc5a4be commit a56454d

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

cyctl/internal/get/resources.go

+30-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package get
22

33
import (
44
"fmt"
5-
"strings"
65

76
"github.com/cyclops-ui/cyclops/cyclops-ctrl/pkg/cluster/k8sclient"
87
"github.com/cyclops-ui/cycops-cyctl/internal/kubeconfig"
@@ -39,12 +38,37 @@ func listResources(clientset *k8sclient.KubernetesClient, moduleNames []string)
3938
return
4039
}
4140

42-
headerSpacing := 20
43-
output := "KIND" + strings.Repeat(" ", 16) + " NAME\n"
44-
fmt.Print(output)
41+
maxKindLen := len("KIND")
42+
maxNameLen := len("NAME")
43+
maxNamespaceLen := len("NAMESPACE")
44+
45+
for _, resource := range resources {
46+
if len(resource.GetKind()) > maxKindLen {
47+
maxKindLen = len(resource.GetKind())
48+
}
49+
if len(resource.GetName()) > maxNameLen {
50+
maxNameLen = len(resource.GetName())
51+
}
52+
if len(resource.GetNamespace()) > maxNamespaceLen {
53+
maxNamespaceLen = len(resource.GetNamespace())
54+
}
55+
}
56+
maxKindLen = maxKindLen + 2
57+
maxNameLen = maxNameLen + 2
58+
maxNamespaceLen = maxNamespaceLen + 2
59+
60+
// Step 2: Print the header with proper spacing
61+
header := fmt.Sprintf("%-*s %-*s %-*s\n",
62+
maxKindLen, "KIND",
63+
maxNamespaceLen, "NAMESPACE", maxNameLen, "NAME")
64+
fmt.Print(header)
65+
66+
// Step 3: Print each resource with calculated spacing
4567
for _, resource := range resources {
46-
nameSpacing := max(0, headerSpacing-len(resource.GetKind()))
47-
fmt.Printf("%s"+strings.Repeat(" ", nameSpacing)+" %s\n", resource.GetKind(), resource.GetName())
68+
fmt.Printf("%-*s %-*s %-*s\n",
69+
maxKindLen, resource.GetKind(),
70+
maxNamespaceLen, resource.GetNamespace(), maxNameLen, resource.GetName(),
71+
)
4872
}
4973

5074
}

0 commit comments

Comments
 (0)