Skip to content

Commit 482db10

Browse files
committed
add percentages
1 parent 789c6de commit 482db10

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

cli/clistat/stat.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ func (r *Result) String() string {
120120
_, _ = sb.WriteString(prefix)
121121
_, _ = sb.WriteString(r.Unit)
122122
}
123+
if r.Total != (*float64)(nil) && *r.Total != 0.0 {
124+
_, _ = sb.WriteString(" (")
125+
_, _ = sb.WriteString(strconv.FormatFloat(100.0*r.Used/(*r.Total), 'f', 0, 64))
126+
_, _ = sb.WriteString("%)")
127+
}
123128
return sb.String()
124129
}
125130

cli/clistat/stat_internal_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func TestResultString(t *testing.T) {
1818
Result Result
1919
}{
2020
{
21-
Expected: "1.2/5.7 quatloos",
21+
Expected: "1.2/5.7 quatloos (22%)",
2222
Result: Result{Used: 1.234, Total: ptr.To(5.678), Unit: "quatloos"},
2323
},
2424
{

0 commit comments

Comments
 (0)