From 8f5194c7154b20965250f6333226a18e225647dd Mon Sep 17 00:00:00 2001 From: Javier Blazquez Date: Tue, 20 Sep 2016 16:03:22 -0700 Subject: Added --description option --- README.md | 48 +++++++++++++++++++++------------------ drive/mkdir.go | 13 +++++++---- drive/update.go | 23 ++++++++++--------- drive/upload.go | 54 +++++++++++++++++++++++-------------------- gdrive.go | 22 +++++++++++++++++- handlers_drive.go | 68 +++++++++++++++++++++++++++++-------------------------- 6 files changed, 133 insertions(+), 95 deletions(-) diff --git a/README.md b/README.md index 9a1428e..c031d4d 100644 --- a/README.md +++ b/README.md @@ -195,15 +195,16 @@ global: --access-token Oauth access token, only recommended for short-lived requests because of short lifetime (for advanced users) options: - -r, --recursive Upload directory recursively - -p, --parent Parent id, used to upload file to a specific directory, can be specified multiple times to give many parents - --name Filename - --no-progress Hide progress - --mime Force mime type - --share Share file - --delete Delete local file when upload is successful - --timeout Set timeout in seconds, use 0 for no timeout. Timeout is reached when no data is transferred in set amount of seconds, default: 300 - --chunksize Set chunk size in bytes, default: 8388608 + -r, --recursive Upload directory recursively + -p, --parent Parent id, used to upload file to a specific directory, can be specified multiple times to give many parents + --name Filename + --description File description + --no-progress Hide progress + --mime Force mime type + --share Share file + --delete Delete local file when upload is successful + --timeout Set timeout in seconds, use 0 for no timeout. Timeout is reached when no data is transferred in set amount of seconds, default: 300 + --chunksize Set chunk size in bytes, default: 8388608 ``` #### Upload file from stdin @@ -216,12 +217,13 @@ global: --access-token Oauth access token, only recommended for short-lived requests because of short lifetime (for advanced users) options: - -p, --parent Parent id, used to upload file to a specific directory, can be specified multiple times to give many parents - --chunksize Set chunk size in bytes, default: 8388608 - --mime Force mime type - --share Share file - --timeout Set timeout in seconds, use 0 for no timeout. Timeout is reached when no data is transferred in set amount of seconds, default: 300 - --no-progress Hide progress + -p, --parent Parent id, used to upload file to a specific directory, can be specified multiple times to give many parents + --chunksize Set chunk size in bytes, default: 8388608 + --description File description + --mime Force mime type + --share Share file + --timeout Set timeout in seconds, use 0 for no timeout. Timeout is reached when no data is transferred in set amount of seconds, default: 300 + --no-progress Hide progress ``` #### Update file, this creates a new revision of the file @@ -234,12 +236,13 @@ global: --access-token Oauth access token, only recommended for short-lived requests because of short lifetime (for advanced users) options: - -p, --parent Parent id, used to upload file to a specific directory, can be specified multiple times to give many parents - --name Filename - --no-progress Hide progress - --mime Force mime type - --timeout Set timeout in seconds, use 0 for no timeout. Timeout is reached when no data is transferred in set amount of seconds, default: 300 - --chunksize Set chunk size in bytes, default: 8388608 + -p, --parent Parent id, used to upload file to a specific directory, can be specified multiple times to give many parents + --name Filename + --description File description + --no-progress Hide progress + --mime Force mime type + --timeout Set timeout in seconds, use 0 for no timeout. Timeout is reached when no data is transferred in set amount of seconds, default: 300 + --chunksize Set chunk size in bytes, default: 8388608 ``` #### Show file info @@ -265,7 +268,8 @@ global: --access-token Oauth access token, only recommended for short-lived requests because of short lifetime (for advanced users) options: - -p, --parent Parent id of created directory, can be specified multiple times to give many parents + -p, --parent Parent id of created directory, can be specified multiple times to give many parents + --description Directory description ``` #### Share file or directory diff --git a/drive/mkdir.go b/drive/mkdir.go index 8eea210..05d5191 100644 --- a/drive/mkdir.go +++ b/drive/mkdir.go @@ -9,9 +9,10 @@ import ( const DirectoryMimeType = "application/vnd.google-apps.folder" type MkdirArgs struct { - Out io.Writer - Name string - Parents []string + Out io.Writer + Name string + Description string + Parents []string } func (self *Drive) Mkdir(args MkdirArgs) error { @@ -24,7 +25,11 @@ func (self *Drive) Mkdir(args MkdirArgs) error { } func (self *Drive) mkdir(args MkdirArgs) (*drive.File, error) { - dstFile := &drive.File{Name: args.Name, MimeType: DirectoryMimeType} + dstFile := &drive.File{ + Name: args.Name, + Description: args.Description, + MimeType: DirectoryMimeType, + } // Set parent folders dstFile.Parents = args.Parents diff --git a/drive/update.go b/drive/update.go index 2ab684e..f496f52 100644 --- a/drive/update.go +++ b/drive/update.go @@ -11,16 +11,17 @@ import ( ) type UpdateArgs struct { - Out io.Writer - Progress io.Writer - Id string - Path string - Name string - Parents []string - Mime string - Recursive bool - ChunkSize int64 - Timeout time.Duration + Out io.Writer + Progress io.Writer + Id string + Path string + Name string + Description string + Parents []string + Mime string + Recursive bool + ChunkSize int64 + Timeout time.Duration } func (self *Drive) Update(args UpdateArgs) error { @@ -32,7 +33,7 @@ func (self *Drive) Update(args UpdateArgs) error { defer srcFile.Close() // Instantiate empty drive file - dstFile := &drive.File{} + dstFile := &drive.File{Description: args.Description} // Use provided file name or use filename if args.Name == "" { diff --git a/drive/upload.go b/drive/upload.go index dbf068c..a4482e2 100644 --- a/drive/upload.go +++ b/drive/upload.go @@ -12,17 +12,18 @@ import ( ) type UploadArgs struct { - Out io.Writer - Progress io.Writer - Path string - Name string - Parents []string - Mime string - Recursive bool - Share bool - Delete bool - ChunkSize int64 - Timeout time.Duration + Out io.Writer + Progress io.Writer + Path string + Name string + Description string + Parents []string + Mime string + Recursive bool + Share bool + Delete bool + ChunkSize int64 + Timeout time.Duration } func (self *Drive) Upload(args UploadArgs) error { @@ -110,9 +111,10 @@ func (self *Drive) uploadDirectory(args UploadArgs) error { fmt.Fprintf(args.Out, "Creating directory %s\n", srcFileInfo.Name()) // Make directory on drive f, err := self.mkdir(MkdirArgs{ - Out: args.Out, - Name: srcFileInfo.Name(), - Parents: args.Parents, + Out: args.Out, + Name: srcFileInfo.Name(), + Parents: args.Parents, + Description: args.Description, }) if err != nil { return err @@ -129,6 +131,7 @@ func (self *Drive) uploadDirectory(args UploadArgs) error { newArgs := args newArgs.Path = filepath.Join(args.Path, name) newArgs.Parents = []string{f.Id} + newArgs.Description = "" // Upload err = self.uploadRecursive(newArgs) @@ -150,7 +153,7 @@ func (self *Drive) uploadFile(args UploadArgs) (*drive.File, int64, error) { defer srcFile.Close() // Instantiate empty drive file - dstFile := &drive.File{} + dstFile := &drive.File{Description: args.Description} // Use provided file name or use filename if args.Name == "" { @@ -196,15 +199,16 @@ func (self *Drive) uploadFile(args UploadArgs) (*drive.File, int64, error) { } type UploadStreamArgs struct { - Out io.Writer - In io.Reader - Name string - Parents []string - Mime string - Share bool - ChunkSize int64 - Progress io.Writer - Timeout time.Duration + Out io.Writer + In io.Reader + Name string + Description string + Parents []string + Mime string + Share bool + ChunkSize int64 + Progress io.Writer + Timeout time.Duration } func (self *Drive) UploadStream(args UploadStreamArgs) error { @@ -213,7 +217,7 @@ func (self *Drive) UploadStream(args UploadStreamArgs) error { } // Instantiate empty drive file - dstFile := &drive.File{Name: args.Name} + dstFile := &drive.File{Name: args.Name, Description: args.Description} // Set mime type if provided if args.Mime != "" { diff --git a/gdrive.go b/gdrive.go index 4833eaa..971dc4c 100644 --- a/gdrive.go +++ b/gdrive.go @@ -213,6 +213,11 @@ func main() { Patterns: []string{"--name"}, Description: "Filename", }, + cli.StringFlag{ + Name: "description", + Patterns: []string{"--description"}, + Description: "File description", + }, cli.BoolFlag{ Name: "noProgress", Patterns: []string{"--no-progress"}, @@ -269,6 +274,11 @@ func main() { Description: fmt.Sprintf("Set chunk size in bytes, default: %d", DefaultUploadChunkSize), DefaultValue: DefaultUploadChunkSize, }, + cli.StringFlag{ + Name: "description", + Patterns: []string{"--description"}, + Description: "File description", + }, cli.StringFlag{ Name: "mime", Patterns: []string{"--mime"}, @@ -312,6 +322,11 @@ func main() { Patterns: []string{"--name"}, Description: "Filename", }, + cli.StringFlag{ + Name: "description", + Patterns: []string{"--description"}, + Description: "File description", + }, cli.BoolFlag{ Name: "noProgress", Patterns: []string{"--no-progress"}, @@ -366,6 +381,11 @@ func main() { Patterns: []string{"-p", "--parent"}, Description: "Parent id of created directory, can be specified multiple times to give many parents", }, + cli.StringFlag{ + Name: "description", + Patterns: []string{"--description"}, + Description: "Directory description", + }, ), }, }, @@ -397,7 +417,7 @@ func main() { Name: "domain", Patterns: []string{"--domain"}, Description: "The name of Google Apps domain. Requires 'domain' as type", - }, + }, cli.BoolFlag{ Name: "discoverable", Patterns: []string{"--discoverable"}, diff --git a/handlers_drive.go b/handlers_drive.go index 5b651ba..5240566 100644 --- a/handlers_drive.go +++ b/handlers_drive.go @@ -115,17 +115,18 @@ func uploadHandler(ctx cli.Context) { args := ctx.Args() checkUploadArgs(args) err := newDrive(args).Upload(drive.UploadArgs{ - Out: os.Stdout, - Progress: progressWriter(args.Bool("noProgress")), - Path: args.String("path"), - Name: args.String("name"), - Parents: args.StringSlice("parent"), - Mime: args.String("mime"), - Recursive: args.Bool("recursive"), - Share: args.Bool("share"), - Delete: args.Bool("delete"), - ChunkSize: args.Int64("chunksize"), - Timeout: durationInSeconds(args.Int64("timeout")), + Out: os.Stdout, + Progress: progressWriter(args.Bool("noProgress")), + Path: args.String("path"), + Name: args.String("name"), + Description: args.String("description"), + Parents: args.StringSlice("parent"), + Mime: args.String("mime"), + Recursive: args.Bool("recursive"), + Share: args.Bool("share"), + Delete: args.Bool("delete"), + ChunkSize: args.Int64("chunksize"), + Timeout: durationInSeconds(args.Int64("timeout")), }) checkErr(err) } @@ -133,15 +134,16 @@ func uploadHandler(ctx cli.Context) { func uploadStdinHandler(ctx cli.Context) { args := ctx.Args() err := newDrive(args).UploadStream(drive.UploadStreamArgs{ - Out: os.Stdout, - In: os.Stdin, - Name: args.String("name"), - Parents: args.StringSlice("parent"), - Mime: args.String("mime"), - Share: args.Bool("share"), - ChunkSize: args.Int64("chunksize"), - Timeout: durationInSeconds(args.Int64("timeout")), - Progress: progressWriter(args.Bool("noProgress")), + Out: os.Stdout, + In: os.Stdin, + Name: args.String("name"), + Description: args.String("description"), + Parents: args.StringSlice("parent"), + Mime: args.String("mime"), + Share: args.Bool("share"), + ChunkSize: args.Int64("chunksize"), + Timeout: durationInSeconds(args.Int64("timeout")), + Progress: progressWriter(args.Bool("noProgress")), }) checkErr(err) } @@ -167,15 +169,16 @@ func uploadSyncHandler(ctx cli.Context) { func updateHandler(ctx cli.Context) { args := ctx.Args() err := newDrive(args).Update(drive.UpdateArgs{ - Out: os.Stdout, - Id: args.String("fileId"), - Path: args.String("path"), - Name: args.String("name"), - Parents: args.StringSlice("parent"), - Mime: args.String("mime"), - Progress: progressWriter(args.Bool("noProgress")), - ChunkSize: args.Int64("chunksize"), - Timeout: durationInSeconds(args.Int64("timeout")), + Out: os.Stdout, + Id: args.String("fileId"), + Path: args.String("path"), + Name: args.String("name"), + Description: args.String("description"), + Parents: args.StringSlice("parent"), + Mime: args.String("mime"), + Progress: progressWriter(args.Bool("noProgress")), + ChunkSize: args.Int64("chunksize"), + Timeout: durationInSeconds(args.Int64("timeout")), }) checkErr(err) } @@ -229,9 +232,10 @@ func listRevisionsHandler(ctx cli.Context) { func mkdirHandler(ctx cli.Context) { args := ctx.Args() err := newDrive(args).Mkdir(drive.MkdirArgs{ - Out: os.Stdout, - Name: args.String("name"), - Parents: args.StringSlice("parent"), + Out: os.Stdout, + Name: args.String("name"), + Description: args.String("description"), + Parents: args.StringSlice("parent"), }) checkErr(err) } -- cgit v1.2.3