mirror of
https://github.com/rclone/rclone.git
synced 2024-12-04 14:26:42 +01:00
32 lines
688 B
Go
32 lines
688 B
Go
|
package size
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
|
||
|
"github.com/ncw/rclone/cmd"
|
||
|
"github.com/ncw/rclone/fs"
|
||
|
"github.com/spf13/cobra"
|
||
|
)
|
||
|
|
||
|
func init() {
|
||
|
cmd.Root.AddCommand(sizeCmd)
|
||
|
}
|
||
|
|
||
|
var sizeCmd = &cobra.Command{
|
||
|
Use: "size remote:path",
|
||
|
Short: `Prints the total size and number of objects in remote:path.`,
|
||
|
Run: func(command *cobra.Command, args []string) {
|
||
|
cmd.CheckArgs(1, 1, command, args)
|
||
|
fsrc := cmd.NewFsSrc(args)
|
||
|
cmd.Run(false, command, func() error {
|
||
|
objects, size, err := fs.Count(fsrc)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
fmt.Printf("Total objects: %d\n", objects)
|
||
|
fmt.Printf("Total size: %s (%d Bytes)\n", fs.SizeSuffix(size).Unit("Bytes"), size)
|
||
|
return nil
|
||
|
})
|
||
|
},
|
||
|
}
|