mirror of
https://github.com/rclone/rclone
synced 2024-11-07 04:16:58 +01:00
f3f48d7d49
This unifies the 3 methods of reading config * command line * environment variable * config file And allows them all to be configured in all places. This is done by making the []fs.Option in the backend registration be the master source of what the backend options are. The backend changes are: * Use the new configmap.Mapper parameter * Use configstruct to parse it into an Options struct * Add all config to []fs.Option including defaults and help * Remove all uses of pflag * Remove all uses of config.FileGet
56 lines
1.0 KiB
Go
56 lines
1.0 KiB
Go
// +build !plan9
|
|
|
|
package cachestats
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/ncw/rclone/backend/cache"
|
|
"github.com/ncw/rclone/cmd"
|
|
"github.com/pkg/errors"
|
|
"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
|
|
`,
|
|
Run: func(command *cobra.Command, args []string) {
|
|
cmd.CheckArgs(1, 1, command, args)
|
|
|
|
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 errors.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
|
|
})
|
|
},
|
|
}
|