diff options
| -rw-r--r-- | drive/about.go | 50 | ||||
| -rw-r--r-- | gdrive.go | 18 | ||||
| -rw-r--r-- | handlers.go | 10 |
3 files changed, 75 insertions, 3 deletions
diff --git a/drive/about.go b/drive/about.go new file mode 100644 index 0000000..0dbeca2 --- /dev/null +++ b/drive/about.go @@ -0,0 +1,50 @@ +package drive + +import ( + "fmt" + "os" + "text/tabwriter" +) + +type AboutArgs struct { + SizeInBytes bool + ImportFormats bool + ExportFormats bool +} + +func (self *Drive) About(args AboutArgs) { + about, err := self.service.About.Get().Fields("exportFormats", "importFormats", "maxImportSizes", "maxUploadSize", "storageQuota", "user").Do() + errorF(err, "Failed to get about %s", err) + + if args.ExportFormats { + printSupportedFormats(about.ExportFormats) + return + } + + if args.ImportFormats { + printSupportedFormats(about.ImportFormats) + return + } + + user := about.User + quota := about.StorageQuota + + fmt.Printf("User: %s, %s\n", user.DisplayName, user.EmailAddress) + fmt.Printf("Used: %s\n", formatSize(quota.UsageInDrive, args.SizeInBytes)) + fmt.Printf("Free: %s\n", formatSize(quota.Limit - quota.UsageInDrive, args.SizeInBytes)) + fmt.Printf("Total: %s\n", formatSize(quota.Limit, args.SizeInBytes)) + fmt.Printf("Max upload size: %s\n", formatSize(about.MaxUploadSize, args.SizeInBytes)) +} + +func printSupportedFormats(formats map[string][]string) { + w := new(tabwriter.Writer) + w.Init(os.Stdout, 0, 0, 3, ' ', 0) + + fmt.Fprintln(w, "From\tTo") + + for from, toFormats := range formats { + fmt.Fprintf(w, "%s\t%s\n", from, formatList(toFormats)) + } + + w.Flush() +} @@ -246,9 +246,9 @@ func main() { }, }, &cli.Handler{ - Pattern: "[global options] quota [options]", - Description: "Show free space", - Callback: handler, + Pattern: "[global options] about [options]", + Description: "Google drive metadata, quota usage, import/export formats", + Callback: aboutHandler, Flags: cli.Flags{ "global options": globalFlags, "options": []cli.Flag{ @@ -258,6 +258,18 @@ func main() { Description: "Show size in bytes", OmitValue: true, }, + cli.BoolFlag{ + Name: "exportFormats", + Patterns: []string{"--export"}, + Description: "Show supported export formats", + OmitValue: true, + }, + cli.BoolFlag{ + Name: "importFormats", + Patterns: []string{"--import"}, + Description: "Show supported import formats", + OmitValue: true, + }, }, }, }, diff --git a/handlers.go b/handlers.go index 9325026..d4a97d8 100644 --- a/handlers.go +++ b/handlers.go @@ -99,6 +99,16 @@ func deleteHandler(ctx cli.Context) { }) } +func aboutHandler(ctx cli.Context) { + args := ctx.Args() + + newDrive(args).About(drive.AboutArgs{ + SizeInBytes: args.Bool("sizeInBytes"), + ImportFormats: args.Bool("importFormats"), + ExportFormats: args.Bool("exportFormats"), + }) +} + func handler(ctx cli.Context) { fmt.Println("handler...") } |
