Skip to content

Commit 2e5a65b

Browse files
authored
display store size with human-friendly format (#70)
1 parent 771c378 commit 2e5a65b

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
github.com/charmbracelet/bubbles v0.14.0
99
github.com/charmbracelet/bubbletea v0.22.1
1010
github.com/charmbracelet/lipgloss v0.6.0
11+
github.com/dustin/go-humanize v1.0.0
1112
github.com/emirpasic/gods v1.18.1
1213
github.com/fatih/color v1.13.0
1314
github.com/go-openapi/errors v0.20.3

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
8080
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
8181
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
8282
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
83+
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
84+
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
8385
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
8486
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
8587
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=

internal/cli/dataimport/list.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"tidbcloud-cli/internal/service/cloud"
2626
importModel "tidbcloud-cli/pkg/tidbcloud/import/models"
2727

28+
"github.com/dustin/go-humanize"
2829
"github.com/juju/errors"
2930
"github.com/spf13/cobra"
3031
)
@@ -150,7 +151,7 @@ func ListCmd(h *internal.Helper) *cobra.Command {
150151
item.CreatedAt.String(),
151152
*item.SourceURL,
152153
string(*item.DataFormat),
153-
fmt.Sprintf("%sB", *item.TotalSize),
154+
convertToStoreSize(*item.TotalSize),
154155
})
155156
}
156157

@@ -172,3 +173,11 @@ func ListCmd(h *internal.Helper) *cobra.Command {
172173
listCmd.Flags().StringP(flag.Output, flag.OutputShort, output.HumanFormat, "Output format. One of: human, json. For the complete result, please use json format.")
173174
return listCmd
174175
}
176+
177+
func convertToStoreSize(totalSize string) string {
178+
size, err := strconv.ParseUint(totalSize, 10, 64)
179+
if err != nil {
180+
return "NaN"
181+
}
182+
return humanize.IBytes(size)
183+
}

0 commit comments

Comments
 (0)