diff options
| author | Petter Rasmussen | 2016-01-23 22:38:45 +0100 | 
|---|---|---|
| committer | Petter Rasmussen | 2016-01-23 22:38:45 +0100 | 
| commit | 2304f9ae29a490231b8ba38d346de0754c4a7fd4 (patch) | |
| tree | 76e3eb520bbe1b30c1e3835ccc7d0fec9dbac3c9 | |
| parent | e6dd66c5722e37a4d2ea7000ce4d1f4090af9cc7 (diff) | |
| download | gdrive-2304f9ae29a490231b8ba38d346de0754c4a7fd4.tar.bz2 | |
Give about import/export own handlers
| -rw-r--r-- | drive/about.go | 42 | ||||
| -rw-r--r-- | gdrive.go | 30 | ||||
| -rw-r--r-- | handlers_drive.go | 18 | 
3 files changed, 61 insertions, 29 deletions
| diff --git a/drive/about.go b/drive/about.go index dea927c..01d7073 100644 --- a/drive/about.go +++ b/drive/about.go @@ -9,26 +9,14 @@ import (  type AboutArgs struct {      Out io.Writer      SizeInBytes bool -    ImportFormats bool -    ExportFormats bool  }  func (self *Drive) About(args AboutArgs) (err error) { -    about, err := self.service.About.Get().Fields("exportFormats", "importFormats", "maxImportSizes", "maxUploadSize", "storageQuota", "user").Do() +    about, err := self.service.About.Get().Fields("maxImportSizes", "maxUploadSize", "storageQuota", "user").Do()      if err != nil {          return fmt.Errorf("Failed to get about: %s", err)      } -    if args.ExportFormats { -        printSupportedFormats(args.Out, about.ExportFormats) -        return -    } - -    if args.ImportFormats { -        printSupportedFormats(args.Out, about.ImportFormats) -        return -    } -      user := about.User      quota := about.StorageQuota @@ -40,7 +28,33 @@ func (self *Drive) About(args AboutArgs) (err error) {      return  } -func printSupportedFormats(out io.Writer, formats map[string][]string) { +type AboutImportArgs struct { +    Out io.Writer +} + +func (self *Drive) AboutImport(args AboutImportArgs) (err error) { +    about, err := self.service.About.Get().Fields("importFormats").Do() +    if err != nil { +        return fmt.Errorf("Failed to get about: %s", err) +    } +    printAboutFormats(args.Out, about.ImportFormats) +    return +} + +type AboutExportArgs struct { +    Out io.Writer +} + +func (self *Drive) AboutExport(args AboutExportArgs) (err error) { +    about, err := self.service.About.Get().Fields("exportFormats").Do() +    if err != nil { +        return fmt.Errorf("Failed to get about: %s", err) +    } +    printAboutFormats(args.Out, about.ExportFormats) +    return +} + +func printAboutFormats(out io.Writer, formats map[string][]string) {      w := new(tabwriter.Writer)      w.Init(out, 0, 0, 3, ' ', 0) @@ -392,7 +392,7 @@ func main() {          },          &cli.Handler{              Pattern: "[global options] about [options]", -            Description: "Google drive metadata, quota usage, import/export formats", +            Description: "Google drive metadata, quota usage",              Callback: aboutHandler,              Flags: cli.Flags{                  "global options": globalFlags, @@ -403,22 +403,26 @@ 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, -                    },                  },              },          },          &cli.Handler{ +            Pattern: "[global options] about import", +            Description: "Show supported import formats", +            Callback: aboutImportHandler, +            Flags: cli.Flags{ +                "global options": globalFlags, +            }, +        }, +        &cli.Handler{ +            Pattern: "[global options] about export", +            Description: "Show supported export formats", +            Callback: aboutExportHandler, +            Flags: cli.Flags{ +                "global options": globalFlags, +            }, +        }, +        &cli.Handler{              Pattern: "version",              Description: "Print application version",              Callback: printVersion, diff --git a/handlers_drive.go b/handlers_drive.go index eeb997f..d454b4f 100644 --- a/handlers_drive.go +++ b/handlers_drive.go @@ -179,8 +179,22 @@ func aboutHandler(ctx cli.Context) {      err := newDrive(args).About(drive.AboutArgs{          Out: os.Stdout,          SizeInBytes: args.Bool("sizeInBytes"), -        ImportFormats: args.Bool("importFormats"), -        ExportFormats: args.Bool("exportFormats"), +    }) +    checkErr(err) +} + +func aboutImportHandler(ctx cli.Context) { +    args := ctx.Args() +    err := newDrive(args).AboutImport(drive.AboutImportArgs{ +        Out: os.Stdout, +    }) +    checkErr(err) +} + +func aboutExportHandler(ctx cli.Context) { +    args := ctx.Args() +    err := newDrive(args).AboutExport(drive.AboutExportArgs{ +        Out: os.Stdout,      })      checkErr(err)  } | 
