Skip to content

Commit

Permalink
Create printTable
Browse files Browse the repository at this point in the history
  • Loading branch information
DalianisDim committed Jun 5, 2023
1 parent d2edd71 commit ab219d9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
17 changes: 16 additions & 1 deletion cmd/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ This file is part of CLI application keyvalDetector
*/
package cmd

import "fmt"
import (
"fmt"
"os"

"github.com/olekukonko/tablewriter"
)

func printSlice(s []string) {
fmt.Printf("len=%d cap=%d %v\n", len(s), cap(s), s)
Expand All @@ -24,3 +29,13 @@ func colorPrint(colorCode int, input string) {
colored := fmt.Sprintf("\x1b[%dm%s\x1b[0m", colorCode, input)
fmt.Print(colored)
}

func printTable(tabledata [][]string) {
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Name", "Namespace"})

for _, v := range tabledata {
table.Append(v)
}
table.Render() // Send output
}
21 changes: 3 additions & 18 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"os"
"time"

"github.com/olekukonko/tablewriter"

"github.com/briandowns/spinner"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -201,25 +199,12 @@ func keyvalDetector() error {

s.Stop() // stop the spinner

// Construct ConfigMaps table
configMapsTable := tablewriter.NewWriter(os.Stdout)
configMapsTable.SetHeader([]string{"Name", "Namespace"})

for _, v := range configMapsOut {
configMapsTable.Append(v)
}
// Render to stdout
colorPrint(31, "Unused ConfigMaps: \n")
configMapsTable.Render() // Send output
printTable(configMapsOut)

// Construct Secrets table
secretsTable := tablewriter.NewWriter(os.Stdout)
secretsTable.SetHeader([]string{"Name", "Namespace"})

for _, v := range secretsOut {
secretsTable.Append(v)
}
colorPrint(31, "\nUnused Secrets: \n")
secretsTable.Render() // Send output
printTable(secretsOut)

return nil
}
Expand Down

0 comments on commit ab219d9

Please sign in to comment.