diff options
| author | Petter Rasmussen | 2016-01-17 22:50:26 +0100 |
|---|---|---|
| committer | Petter Rasmussen | 2016-01-17 22:50:26 +0100 |
| commit | 742c5a2f7b16a5323eddfa51cbd387c504d7e02a (patch) | |
| tree | c5d8896a2220bebcb4b010689a307245e706ac69 /drive | |
| parent | f4dd433b66f7d25bca32df758e541c0eb948669b (diff) | |
| download | gdrive-742c5a2f7b16a5323eddfa51cbd387c504d7e02a.tar.bz2 | |
Implement about
Diffstat (limited to 'drive')
| -rw-r--r-- | drive/about.go | 50 |
1 files changed, 50 insertions, 0 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() +} |
