Skip to content

Commit

Permalink
optimize: hide repeated lines
Browse files Browse the repository at this point in the history
  • Loading branch information
mandochen committed Jun 14, 2023
1 parent 0962ace commit 5828996
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/spf13/cobra"
)

const version = "0.6.2"
const version = "0.6.3"

var rootCmd *cobra.Command

Expand Down
18 changes: 16 additions & 2 deletions kubectl_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,27 @@ func (ki *KubeImage) tableRender() {
table.SetAutoMergeCells(true)
table.SetRowLine(true)

entities := ki.groupBy()
entities := ki.getGroupByEntities()
for _, entity := range entities {
table.Append(entity.selectBy(ki.columns))
table.Append(entity)
}
table.Render()
}

func (ki *KubeImage) getGroupByEntities() [][]string {
set := make(map[string]struct{})
dst := make([][]string, 0)
for _, entity := range ki.groupBy() {
line := strings.Join(entity.selectBy(ki.columns), "||")
_, ok := set[line]
if !ok {
set[line] = struct{}{}
dst = append(dst, strings.Split(line, "||"))
}
}
return dst
}

func (ki *KubeImage) jsonRender() {
entities := ki.groupBy()
records := make([]ImageEntity, 0, len(entities))
Expand Down

0 comments on commit 5828996

Please sign in to comment.