@@ -2,7 +2,6 @@ package get
2
2
3
3
import (
4
4
"fmt"
5
- "strings"
6
5
7
6
"github.com/cyclops-ui/cyclops/cyclops-ctrl/pkg/cluster/k8sclient"
8
7
"github.com/cyclops-ui/cycops-cyctl/internal/kubeconfig"
@@ -39,14 +38,37 @@ func listResources(clientset *k8sclient.KubernetesClient, moduleNames []string)
39
38
return
40
39
}
41
40
42
- headerSpacing := 20
43
- output := "KIND" + strings .Repeat (" " , 16 ) + " NAME" + strings .Repeat (" " , 16 ) + " NAMESPACE\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
45
67
for _ , resource := range resources {
46
- nameSpacing := max ( 0 , headerSpacing - len ( resource . GetKind ()))
47
- namespaceSpacing := max ( 0 , headerSpacing - len ( resource .GetName ()))
48
- fmt . Printf ( "%s" + strings . Repeat ( " " , nameSpacing ) + " %s" + strings . Repeat ( " " , namespaceSpacing ) + "%s \n " ,
49
- resource . GetKind (), resource . GetName (), resource . GetNamespace () )
68
+ fmt . Printf ( "%-*s %-*s %-*s \n " ,
69
+ maxKindLen , resource .GetKind (),
70
+ maxNamespaceLen , resource . GetNamespace (), maxNameLen , resource . GetName () ,
71
+ )
50
72
}
51
73
52
74
}
0 commit comments