提交 cd8c4ee8 作者: Kevin Atkinson

Use tabwritter for better formatted output.

License: MIT
Signed-off-by: 's avatarKevin Atkinson <k@kevina.org>
上级 0f46a34f
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"text/tabwriter"
bstore "github.com/ipfs/go-ipfs/blocks/blockstore" bstore "github.com/ipfs/go-ipfs/blocks/blockstore"
cmds "github.com/ipfs/go-ipfs/commands" cmds "github.com/ipfs/go-ipfs/commands"
...@@ -182,21 +183,23 @@ Version string The repo version. ...@@ -182,21 +183,23 @@ Version string The repo version.
} }
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
fmt.Fprintf(buf, "NumObjects \t %d\n", stat.NumObjects) wtr := tabwriter.NewWriter(buf, 0, 0, 1, ' ', 0)
fmt.Fprintf(wtr, "NumObjects:\t%d\n", stat.NumObjects)
sizeInMiB := stat.RepoSize / (1024 * 1024) sizeInMiB := stat.RepoSize / (1024 * 1024)
if human && sizeInMiB > 0 { if human && sizeInMiB > 0 {
fmt.Fprintf(buf, "RepoSize (MiB) \t %d\n", sizeInMiB) fmt.Fprintf(wtr, "RepoSize (MiB):\t%d\n", sizeInMiB)
} else { } else {
fmt.Fprintf(buf, "RepoSize \t %d\n", stat.RepoSize) fmt.Fprintf(wtr, "RepoSize:\t%d\n", stat.RepoSize)
} }
maxSizeInMiB := stat.StorageMax / (1024 * 1024) maxSizeInMiB := stat.StorageMax / (1024 * 1024)
if human && maxSizeInMiB > 0 { if human && maxSizeInMiB > 0 {
fmt.Fprintf(buf, "StorageMax (MiB) \t %d\n", maxSizeInMiB) fmt.Fprintf(wtr, "StorageMax (MiB):\t%d\n", maxSizeInMiB)
} else { } else {
fmt.Fprintf(buf, "StorageMax \t %d\n", stat.StorageMax) fmt.Fprintf(wtr, "StorageMax:\t%d\n", stat.StorageMax)
} }
fmt.Fprintf(buf, "RepoPath \t %s\n", stat.RepoPath) fmt.Fprintf(wtr, "RepoPath:\t%s\n", stat.RepoPath)
fmt.Fprintf(buf, "Version \t %s\n", stat.Version) fmt.Fprintf(wtr, "Version:\t%s\n", stat.Version)
wtr.Flush()
return buf, nil return buf, nil
}, },
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论