@cryptotaxi247 / kubo / commits / cd8c4ee8e

Use tabwritter for better formatted output.

License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>

Kevin Atkinson committed May 11, 2017 at 22:05 UTC cd8c4ee8e0527eb2a4bdb6adf282bc393791908d
1 file changed +10 -7
core/commands/repo.go
+10 -7
@@ -7,6 +7,7 @@ import (
7 "os"
8 "path/filepath"
9 "strings"
10 + "text/tabwriter"
11
12 bstore "github.com/ipfs/go-ipfs/blocks/blockstore"
13 cmds "github.com/ipfs/go-ipfs/commands"
@@ -182,21 +183,23 @@ Version string The repo version.
183 }
184
185 buf := new(bytes.Buffer)
185 - fmt.Fprintf(buf, "NumObjects \t %d\n", stat.NumObjects)
186 + wtr := tabwriter.NewWriter(buf, 0, 0, 1, ' ', 0)
187 + fmt.Fprintf(wtr, "NumObjects:\t%d\n", stat.NumObjects)
188 sizeInMiB := stat.RepoSize / (1024 * 1024)
189 if human && sizeInMiB > 0 {
188 - fmt.Fprintf(buf, "RepoSize (MiB) \t %d\n", sizeInMiB)
190 + fmt.Fprintf(wtr, "RepoSize (MiB):\t%d\n", sizeInMiB)
191 } else {
190 - fmt.Fprintf(buf, "RepoSize \t %d\n", stat.RepoSize)
192 + fmt.Fprintf(wtr, "RepoSize:\t%d\n", stat.RepoSize)
193 }
194 maxSizeInMiB := stat.StorageMax / (1024 * 1024)
195 if human && maxSizeInMiB > 0 {
194 - fmt.Fprintf(buf, "StorageMax (MiB) \t %d\n", maxSizeInMiB)
196 + fmt.Fprintf(wtr, "StorageMax (MiB):\t%d\n", maxSizeInMiB)
197 } else {
196 - fmt.Fprintf(buf, "StorageMax \t %d\n", stat.StorageMax)
198 + fmt.Fprintf(wtr, "StorageMax:\t%d\n", stat.StorageMax)
199 }
198 - fmt.Fprintf(buf, "RepoPath \t %s\n", stat.RepoPath)
199 - fmt.Fprintf(buf, "Version \t %s\n", stat.Version)
200 + fmt.Fprintf(wtr, "RepoPath:\t%s\n", stat.RepoPath)
201 + fmt.Fprintf(wtr, "Version:\t%s\n", stat.Version)
202 + wtr.Flush()
203
204 return buf, nil
205 },