2022-08-28 19:21:57 +08:00
|
|
|
// Package about provides the about command.
|
2018-02-10 04:48:32 +08:00
|
|
|
package about
|
|
|
|
|
|
|
|
import (
|
2019-06-17 16:34:30 +08:00
|
|
|
"context"
|
2018-04-17 05:19:25 +08:00
|
|
|
"encoding/json"
|
2021-11-04 18:12:57 +08:00
|
|
|
"errors"
|
2018-04-17 05:19:25 +08:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
2019-07-29 01:47:38 +08:00
|
|
|
"github.com/rclone/rclone/cmd"
|
|
|
|
"github.com/rclone/rclone/fs"
|
2019-10-11 23:55:04 +08:00
|
|
|
"github.com/rclone/rclone/fs/config/flags"
|
2018-02-10 04:48:32 +08:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2018-04-17 05:19:25 +08:00
|
|
|
var (
|
|
|
|
jsonOutput bool
|
|
|
|
fullOutput bool
|
|
|
|
)
|
|
|
|
|
2018-02-10 04:48:32 +08:00
|
|
|
func init() {
|
2018-04-17 05:19:25 +08:00
|
|
|
cmd.Root.AddCommand(commandDefinition)
|
2019-10-11 23:55:04 +08:00
|
|
|
cmdFlags := commandDefinition.Flags()
|
2023-07-11 01:34:10 +08:00
|
|
|
flags.BoolVarP(cmdFlags, &jsonOutput, "json", "", false, "Format output as JSON", "")
|
|
|
|
flags.BoolVarP(cmdFlags, &fullOutput, "full", "", false, "Full numbers instead of human-readable", "")
|
2018-02-10 04:48:32 +08:00
|
|
|
}
|
|
|
|
|
2018-04-17 05:19:25 +08:00
|
|
|
// printValue formats uv to be output
|
2021-04-03 05:57:41 +08:00
|
|
|
func printValue(what string, uv *int64, isSize bool) {
|
2018-04-17 05:19:25 +08:00
|
|
|
what += ":"
|
|
|
|
if uv == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var val string
|
|
|
|
if fullOutput {
|
|
|
|
val = fmt.Sprintf("%d", *uv)
|
2021-04-03 05:57:41 +08:00
|
|
|
} else if isSize {
|
|
|
|
val = fs.SizeSuffix(*uv).ByteUnit()
|
2018-04-17 05:19:25 +08:00
|
|
|
} else {
|
2021-04-03 05:57:41 +08:00
|
|
|
val = fs.CountSuffix(*uv).String()
|
2018-04-17 05:19:25 +08:00
|
|
|
}
|
|
|
|
fmt.Printf("%-9s%v\n", what, val)
|
|
|
|
}
|
|
|
|
|
|
|
|
var commandDefinition = &cobra.Command{
|
2018-02-10 04:48:32 +08:00
|
|
|
Use: "about remote:",
|
|
|
|
Short: `Get quota information from the remote.`,
|
2024-08-13 00:17:46 +08:00
|
|
|
Long: `Prints quota information about a remote to standard
|
2020-11-27 22:08:52 +08:00
|
|
|
output. The output is typically used, free, quota and trash contents.
|
2018-04-17 05:19:25 +08:00
|
|
|
|
2021-04-07 14:47:29 +08:00
|
|
|
E.g. Typical output from ` + "`rclone about remote:`" + ` is:
|
2018-04-17 05:19:25 +08:00
|
|
|
|
2021-08-22 01:54:21 +08:00
|
|
|
Total: 17 GiB
|
|
|
|
Used: 7.444 GiB
|
|
|
|
Free: 1.315 GiB
|
|
|
|
Trashed: 100.000 MiB
|
|
|
|
Other: 8.241 GiB
|
2018-04-17 05:19:25 +08:00
|
|
|
|
|
|
|
Where the fields are:
|
|
|
|
|
2021-04-03 05:57:41 +08:00
|
|
|
* Total: Total size available.
|
|
|
|
* Used: Total size used.
|
|
|
|
* Free: Total space available to this user.
|
|
|
|
* Trashed: Total space used by trash.
|
|
|
|
* Other: Total amount in other storage (e.g. Gmail, Google Photos).
|
|
|
|
* Objects: Total number of objects in the storage.
|
2018-04-17 05:19:25 +08:00
|
|
|
|
2021-04-03 05:57:41 +08:00
|
|
|
All sizes are in number of bytes.
|
2018-04-17 05:19:25 +08:00
|
|
|
|
2020-11-27 22:08:52 +08:00
|
|
|
Applying a ` + "`--full`" + ` flag to the command prints the bytes in full, e.g.
|
2018-04-17 05:19:25 +08:00
|
|
|
|
|
|
|
Total: 18253611008
|
|
|
|
Used: 7993453766
|
|
|
|
Free: 1411001220
|
|
|
|
Trashed: 104857602
|
|
|
|
Other: 8849156022
|
|
|
|
|
2021-11-04 19:50:43 +08:00
|
|
|
A ` + "`--json`" + ` flag generates conveniently machine-readable output, e.g.
|
2018-04-17 05:19:25 +08:00
|
|
|
|
|
|
|
{
|
|
|
|
"total": 18253611008,
|
|
|
|
"used": 7993453766,
|
|
|
|
"trashed": 104857602,
|
|
|
|
"other": 8849156022,
|
|
|
|
"free": 1411001220
|
|
|
|
}
|
2020-11-27 22:08:52 +08:00
|
|
|
|
2021-04-03 05:57:41 +08:00
|
|
|
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.
|
2020-11-27 22:08:52 +08:00
|
|
|
|
2021-04-03 05:57:41 +08:00
|
|
|
Some backends does not support the ` + "`rclone about`" + ` command at all,
|
|
|
|
see complete list in [documentation](https://rclone.org/overview/#optional-features).
|
2018-02-10 04:48:32 +08:00
|
|
|
`,
|
2022-11-27 06:40:49 +08:00
|
|
|
Annotations: map[string]string{
|
|
|
|
"versionIntroduced": "v1.41",
|
2023-07-11 01:34:10 +08:00
|
|
|
// "groups": "",
|
2022-11-27 06:40:49 +08:00
|
|
|
},
|
2018-02-10 04:48:32 +08:00
|
|
|
Run: func(command *cobra.Command, args []string) {
|
|
|
|
cmd.CheckArgs(1, 1, command, args)
|
2018-04-17 05:19:25 +08:00
|
|
|
f := cmd.NewFsSrc(args)
|
2018-04-19 04:09:34 +08:00
|
|
|
cmd.Run(false, false, command, func() error {
|
2018-04-17 05:19:25 +08:00
|
|
|
doAbout := f.Features().About
|
|
|
|
if doAbout == nil {
|
2021-11-04 18:12:57 +08:00
|
|
|
return fmt.Errorf("%v doesn't support about", f)
|
2018-04-17 05:19:25 +08:00
|
|
|
}
|
2019-06-17 16:34:30 +08:00
|
|
|
u, err := doAbout(context.Background())
|
2018-04-17 05:19:25 +08:00
|
|
|
if err != nil {
|
2022-01-15 05:18:32 +08:00
|
|
|
return fmt.Errorf("about call failed: %w", err)
|
2018-04-17 05:19:25 +08:00
|
|
|
}
|
2019-05-09 21:29:31 +08:00
|
|
|
if u == nil {
|
|
|
|
return errors.New("nil usage returned")
|
|
|
|
}
|
2018-04-17 05:19:25 +08:00
|
|
|
if jsonOutput {
|
|
|
|
out := json.NewEncoder(os.Stdout)
|
|
|
|
out.SetIndent("", "\t")
|
|
|
|
return out.Encode(u)
|
|
|
|
}
|
2021-04-03 05:57:41 +08:00
|
|
|
|
|
|
|
printValue("Total", u.Total, true)
|
|
|
|
printValue("Used", u.Used, true)
|
|
|
|
printValue("Free", u.Free, true)
|
|
|
|
printValue("Trashed", u.Trashed, true)
|
|
|
|
printValue("Other", u.Other, true)
|
|
|
|
printValue("Objects", u.Objects, false)
|
2018-04-17 05:19:25 +08:00
|
|
|
return nil
|
2018-02-10 04:48:32 +08:00
|
|
|
})
|
|
|
|
},
|
|
|
|
}
|