Skip to content

Commit

Permalink
🏘️ updated the displaying of the namespace (#606)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
Abiji-2020 authored Oct 8, 2024
1 parent fc5a4be commit a56454d
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions cyctl/internal/get/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -39,12 +38,37 @@ func listResources(clientset *k8sclient.KubernetesClient, moduleNames []string)
return
}

headerSpacing := 20
output := "KIND" + strings.Repeat(" ", 16) + " NAME\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()))
fmt.Printf("%s"+strings.Repeat(" ", nameSpacing)+" %s\n", resource.GetKind(), resource.GetName())
fmt.Printf("%-*s %-*s %-*s\n",
maxKindLen, resource.GetKind(),
maxNamespaceLen, resource.GetNamespace(), maxNameLen, resource.GetName(),
)
}

}
Expand Down

0 comments on commit a56454d

Please sign in to comment.