From 2a33d28cb99d6e33a7035a3cf45f30e838c89139 Mon Sep 17 00:00:00 2001 From: Wesley Collin Wright Date: Thu, 31 Oct 2019 12:05:55 -0500 Subject: [PATCH] print disk usage as a plain integer when formatting as json (#2946) --- cmd/du-main.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cmd/du-main.go b/cmd/du-main.go index ebfb7d22..1e6a490b 100644 --- a/cmd/du-main.go +++ b/cmd/du-main.go @@ -70,13 +70,15 @@ EXAMPLES: // Structured message depending on the type of console. type duMessage struct { Prefix string `json:"prefix"` - Size string `json:"size"` + Size int64 `json:"size"` Status string `json:"status"` } // Colorized message for console printing. func (r duMessage) String() string { - return fmt.Sprintf("%s\t%s", console.Colorize("Size", r.Size), + humanSize := strings.Join(strings.Fields(humanize.IBytes(uint64(r.Size))), "") + + return fmt.Sprintf("%s\t%s", console.Colorize("Size", humanSize), console.Colorize("Prefix", r.Prefix)) } @@ -141,7 +143,7 @@ func du(urlStr string, depth int, encKeyDB map[string][]prefixSSEPair) (int64, e printMsg(duMessage{ Prefix: strings.Trim(u.Path, "/"), - Size: strings.Join(strings.Fields(humanize.IBytes(uint64(size))), ""), + Size: size, Status: "success", }) }