Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

truenas "github.com/deevus/truenas-go"
"github.com/dustin/go-humanize"
"github.com/spf13/cobra"

"github.com/deevus/pixels/internal/cache"
Expand Down Expand Up @@ -120,7 +121,7 @@ func runCheckpointList(cmd *cobra.Command, args []string) error {
w := newTabWriter(cmd)
fmt.Fprintln(w, "LABEL\tSIZE")
for _, s := range snapshots {
fmt.Fprintf(w, "%s\t%s\n", s.SnapshotName, formatBytes(s.Referenced))
fmt.Fprintf(w, "%s\t%s\n", s.SnapshotName, humanize.IBytes(uint64(s.Referenced)))
}
return w.Flush()
}
Expand Down
22 changes: 0 additions & 22 deletions cmd/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,3 @@ func TestResolveIP(t *testing.T) {
})
}
}

func TestFormatBytes(t *testing.T) {
tests := []struct {
input int64
want string
}{
{0, "0 B"},
{512, "512 B"},
{1024, "1.0 KiB"},
{1536, "1.5 KiB"},
{1048576, "1.0 MiB"},
{13107200, "12.5 MiB"},
{1073741824, "1.0 GiB"},
}
for _, tt := range tests {
t.Run(tt.want, func(t *testing.T) {
if got := formatBytes(tt.input); got != tt.want {
t.Errorf("formatBytes(%d) = %q, want %q", tt.input, got, tt.want)
}
})
}
}
13 changes: 0 additions & 13 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,3 @@ func ensureSSHAuth(cmd *cobra.Command, ctx context.Context, ip, name string) err

return client.WriteAuthorizedKey(ctx, containerName(name), pubKey)
}

func formatBytes(b int64) string {
const unit = 1024
if b < unit {
return fmt.Sprintf("%d B", b)
}
div, exp := int64(unit), 0
for n := b / unit; n >= unit; n /= unit {
div *= unit
exp++
}
return fmt.Sprintf("%.1f %ciB", float64(b)/float64(div), "KMGTPE"[exp])
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ go 1.25.0
require (
github.com/BurntSushi/toml v1.6.0
github.com/deevus/truenas-go v0.4.0
github.com/dustin/go-humanize v1.0.1
github.com/spf13/cobra v1.10.2
)

require (
al.essio.dev/pkg/shellescape v1.6.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/pflag v1.0.9 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ al.essio.dev/pkg/shellescape v1.6.0/go.mod h1:6sIqp7X2P6mThCQ7twERpZTuigpr6KbZWt
github.com/BurntSushi/toml v1.6.0 h1:dRaEfpa2VI55EwlIW72hMRHdWouJeRF7TPYhI+AUQjk=
github.com/BurntSushi/toml v1.6.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/deevus/truenas-go v0.3.0 h1:IuJ7wm+aW0aSmm4AjW8GK6f+8bjKolj9BVd9bTfKeSU=
github.com/deevus/truenas-go v0.3.0/go.mod h1:a5MwZEqT4NE8jwSA9BHONOAO8yH4kCaS5a+d4ad6sLA=
github.com/deevus/truenas-go v0.4.0 h1:gESJ0naqtwzgdN1/gG5wBrp/Lm/5HF8xCBsRcwNgg78=
github.com/deevus/truenas-go v0.4.0/go.mod h1:a5MwZEqT4NE8jwSA9BHONOAO8yH4kCaS5a+d4ad6sLA=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
Expand Down