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