aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetter Rasmussen2016-01-17 22:50:26 +0100
committerPetter Rasmussen2016-01-17 22:50:26 +0100
commit742c5a2f7b16a5323eddfa51cbd387c504d7e02a (patch)
treec5d8896a2220bebcb4b010689a307245e706ac69
parentf4dd433b66f7d25bca32df758e541c0eb948669b (diff)
downloadgdrive-742c5a2f7b16a5323eddfa51cbd387c504d7e02a.tar.bz2
Implement about
-rw-r--r--drive/about.go50
-rw-r--r--gdrive.go18
-rw-r--r--handlers.go10
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()
+}
diff --git a/gdrive.go b/gdrive.go
index c2f2fba..f884b8e 100644
--- a/gdrive.go
+++ b/gdrive.go
@@ -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...")
}