mirror of
https://github.com/rclone/rclone.git
synced 2024-11-25 17:57:44 +08:00
e43b5ce5e5
This is possible now that we no longer support go1.12 and brings rclone into line with standard practices in the Go world. This also removes errors.New and errors.Errorf from lib/errors and prefers the stdlib errors package over lib/errors.
59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
//go:build !plan9 && !js
|
|
// +build !plan9,!js
|
|
|
|
package cachestats
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/rclone/rclone/backend/cache"
|
|
"github.com/rclone/rclone/cmd"
|
|
"github.com/rclone/rclone/fs"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func init() {
|
|
cmd.Root.AddCommand(commandDefinition)
|
|
}
|
|
|
|
var commandDefinition = &cobra.Command{
|
|
Use: "cachestats source:",
|
|
Short: `Print cache stats for a remote`,
|
|
Long: `
|
|
Print cache stats for a remote in JSON format
|
|
`,
|
|
Hidden: true,
|
|
Run: func(command *cobra.Command, args []string) {
|
|
cmd.CheckArgs(1, 1, command, args)
|
|
fs.Logf(nil, `"rclone cachestats" is deprecated, use "rclone backend stats %s" instead`, args[0])
|
|
|
|
fsrc := cmd.NewFsSrc(args)
|
|
cmd.Run(false, false, command, func() error {
|
|
var fsCache *cache.Fs
|
|
fsCache, ok := fsrc.(*cache.Fs)
|
|
if !ok {
|
|
unwrap := fsrc.Features().UnWrap
|
|
if unwrap != nil {
|
|
fsCache, ok = unwrap().(*cache.Fs)
|
|
}
|
|
if !ok {
|
|
return fmt.Errorf("%s: is not a cache remote", fsrc.Name())
|
|
}
|
|
}
|
|
m, err := fsCache.Stats()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
raw, err := json.MarshalIndent(m, "", " ")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
fmt.Printf("%s\n", string(raw))
|
|
return nil
|
|
})
|
|
},
|
|
}
|