about: make human-readable output more consistent with other commands

This commit is contained in:
albertony 2021-04-02 23:57:41 +02:00
parent 774efeabf0
commit 6d25ba7c02

View file

@ -22,11 +22,11 @@ func init() {
cmd.Root.AddCommand(commandDefinition) cmd.Root.AddCommand(commandDefinition)
cmdFlags := commandDefinition.Flags() cmdFlags := commandDefinition.Flags()
flags.BoolVarP(cmdFlags, &jsonOutput, "json", "", false, "Format output as JSON") flags.BoolVarP(cmdFlags, &jsonOutput, "json", "", false, "Format output as JSON")
flags.BoolVarP(cmdFlags, &fullOutput, "full", "", false, "Full numbers instead of SI units") flags.BoolVarP(cmdFlags, &fullOutput, "full", "", false, "Full numbers instead of human-readable")
} }
// printValue formats uv to be output // printValue formats uv to be output
func printValue(what string, uv *int64) { func printValue(what string, uv *int64, isSize bool) {
what += ":" what += ":"
if uv == nil { if uv == nil {
return return
@ -34,8 +34,10 @@ func printValue(what string, uv *int64) {
var val string var val string
if fullOutput { if fullOutput {
val = fmt.Sprintf("%d", *uv) val = fmt.Sprintf("%d", *uv)
} else if isSize {
val = fs.SizeSuffix(*uv).ByteUnit()
} else { } else {
val = fs.SizeSuffix(*uv).String() val = fs.CountSuffix(*uv).String()
} }
fmt.Printf("%-9s%v\n", what, val) fmt.Printf("%-9s%v\n", what, val)
} }
@ -49,23 +51,22 @@ output. The output is typically used, free, quota and trash contents.
E.g. Typical output from ` + "`rclone about remote:`" + ` is: E.g. Typical output from ` + "`rclone about remote:`" + ` is:
Total: 17G Total: 17 GiByte
Used: 7.444G Used: 7.444 GiByte
Free: 1.315G Free: 1.315 GiByte
Trashed: 100.000M Trashed: 100.000 MiByte
Other: 8.241G Other: 8.241 GiByte
Where the fields are: Where the fields are:
* Total: total size available. * Total: Total size available.
* Used: total size used * Used: Total size used.
* Free: total space available to this user. * Free: Total space available to this user.
* Trashed: total space used by trash * Trashed: Total space used by trash.
* Other: total amount in other storage (e.g. Gmail, Google Photos) * Other: Total amount in other storage (e.g. Gmail, Google Photos).
* Objects: total number of objects in the storage * Objects: Total number of objects in the storage.
Not all backends print all fields. Information is not included if it is not All sizes are in number of bytes.
provided by a backend. Where the value is unlimited it is omitted.
Applying a ` + "`--full`" + ` flag to the command prints the bytes in full, e.g. Applying a ` + "`--full`" + ` flag to the command prints the bytes in full, e.g.
@ -85,9 +86,11 @@ A ` + "`--json`" + ` flag generates conveniently computer readable output, e.g.
"free": 1411001220 "free": 1411001220
} }
Not all backends support the ` + "`rclone about`" + ` command. Not all backends print all fields. Information is not included if it is not
provided by a backend. Where the value is unlimited it is omitted.
See [List of backends that do not support about](https://rclone.org/overview/#optional-features) Some backends does not support the ` + "`rclone about`" + ` command at all,
see complete list in [documentation](https://rclone.org/overview/#optional-features).
`, `,
Run: func(command *cobra.Command, args []string) { Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(1, 1, command, args) cmd.CheckArgs(1, 1, command, args)
@ -109,12 +112,13 @@ See [List of backends that do not support about](https://rclone.org/overview/#op
out.SetIndent("", "\t") out.SetIndent("", "\t")
return out.Encode(u) return out.Encode(u)
} }
printValue("Total", u.Total)
printValue("Used", u.Used) printValue("Total", u.Total, true)
printValue("Free", u.Free) printValue("Used", u.Used, true)
printValue("Trashed", u.Trashed) printValue("Free", u.Free, true)
printValue("Other", u.Other) printValue("Trashed", u.Trashed, true)
printValue("Objects", u.Objects) printValue("Other", u.Other, true)
printValue("Objects", u.Objects, false)
return nil return nil
}) })
}, },