diff --git a/cmd/helpers.go b/cmd/helpers.go index 10276c8..2068139 100644 --- a/cmd/helpers.go +++ b/cmd/helpers.go @@ -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) @@ -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 +} diff --git a/cmd/root.go b/cmd/root.go index 206bd64..0933a79 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -10,8 +10,6 @@ import ( "os" "time" - "github.com/olekukonko/tablewriter" - "github.com/briandowns/spinner" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -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 }