Skip to content

Commit

Permalink
update summary. show diff
Browse files Browse the repository at this point in the history
  • Loading branch information
fujiwara committed Oct 25, 2021
1 parent 6d339ab commit 4108e8f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 45 deletions.
45 changes: 0 additions & 45 deletions ecrm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"io"
"log"
"os"
"sort"
Expand All @@ -22,8 +21,6 @@ import (
"github.com/aws/aws-sdk-go-v2/service/lambda"

"github.com/Songmu/prompter"
"github.com/dustin/go-humanize"
"github.com/olekukonko/tablewriter"
)

var untaggedStr = "__UNTAGGED__"
Expand All @@ -36,48 +33,6 @@ type App struct {
region string
}

type summary struct {
repo string
expiredImages int64
totalImages int64
expiredImageSize int64
totalImageSize int64
}

func (s *summary) row() []string {
return []string{
s.repo,
fmt.Sprintf("%d (%s)", s.expiredImages, humanize.Bytes(uint64(s.expiredImageSize))),
fmt.Sprintf("%d (%s)", s.totalImages, humanize.Bytes(uint64(s.totalImageSize))),
}
}

type summaries []*summary

func (s *summaries) print(w io.Writer) {
t := tablewriter.NewWriter(w)
t.SetHeader(s.header())
t.SetBorder(false)
for _, s := range *s {
row := s.row()
if row[1] == "0 (0 B)" {
row[1] = ""
t.Append(row)
} else {
t.Rich(row, []tablewriter.Colors{{}, {tablewriter.FgBlueColor}, {}})
}
}
t.Render()
}

func (s *summaries) header() []string {
return []string{
"repository",
"expired",
"total",
}
}

type taskdef struct {
name string
revision int
Expand Down
58 changes: 58 additions & 0 deletions summary.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package ecrm

import (
"fmt"
"io"
"strings"

"github.com/dustin/go-humanize"
"github.com/olekukonko/tablewriter"
)

type summary struct {
repo string
expiredImages int64
totalImages int64
expiredImageSize int64
totalImageSize int64
}

func (s *summary) row() []string {
return []string{
s.repo,
fmt.Sprintf("%d (%s)", s.totalImages, humanize.Bytes(uint64(s.totalImageSize))),
fmt.Sprintf("%d (%s)", -s.expiredImages, humanize.Bytes(uint64(s.expiredImageSize))),
fmt.Sprintf("%d (%s)", s.totalImages-s.expiredImages, humanize.Bytes(uint64(s.totalImageSize-s.expiredImageSize))),
}
}

type summaries []*summary

func (s *summaries) print(w io.Writer) {
t := tablewriter.NewWriter(w)
t.SetHeader(s.header())
t.SetBorder(false)
for _, s := range *s {
row := s.row()
colors := make([]tablewriter.Colors, len(row))
if strings.HasPrefix(row[2], "0 ") {
row[2] = ""
} else {
colors[2] = tablewriter.Colors{tablewriter.FgBlueColor}
}
if strings.HasPrefix(row[3], "0 ") {
colors[3] = tablewriter.Colors{tablewriter.FgYellowColor}
}
t.Rich(row, colors)
}
t.Render()
}

func (s *summaries) header() []string {
return []string{
"repository",
"total",
"expired",
"keep",
}
}

0 comments on commit 4108e8f

Please sign in to comment.