diff options
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | drive/files.go | 21 | ||||
| -rw-r--r-- | drive/print.go | 4 | ||||
| -rw-r--r-- | drive/types.go | 6 | ||||
| -rw-r--r-- | gdrive.go | 2 | ||||
| -rw-r--r-- | handlers.go | 22 |
6 files changed, 47 insertions, 9 deletions
@@ -7,3 +7,4 @@ _release/bin Session.vim .netrwhist drive_old +foo.txt diff --git a/drive/files.go b/drive/files.go index 6d66234..8a5c7f4 100644 --- a/drive/files.go +++ b/drive/files.go @@ -10,6 +10,8 @@ import ( "golang.org/x/net/context" ) +const DirectoryMimeType = "application/vnd.google-apps.folder" + func (self *Drive) List(args ListFilesArgs) { fileList, err := self.service.Files.List().PageSize(args.MaxFiles).Q(args.Query).Fields("nextPageToken", "files(id,name,size,createdTime)").Do() errorF(err, "Failed listing files: %s\n", err) @@ -116,6 +118,25 @@ func (self *Drive) Info(args FileInfoArgs) { }) } +func (self *Drive) Mkdir(args MkdirArgs) { + dstFile := &drive.File{Name: args.Name, MimeType: DirectoryMimeType} + + // Set parent folder if provided + if args.Parent != "" { + dstFile.Parents = []string{args.Parent} + } + + // Create folder + f, err := self.service.Files.Create(dstFile).Do() + errorF(err, "Failed to create folder: %s", err) + + PrintFileInfo(PrintFileInfoArgs{File: f}) + + //if args.Share { + // self.Share(TODO) + //} +} + //func newFile(args UploadFileArgs) *drive.File { // //} diff --git a/drive/print.go b/drive/print.go index eaabae3..84d4ec7 100644 --- a/drive/print.go +++ b/drive/print.go @@ -59,6 +59,10 @@ func formatList(a []string) string { } func formatSize(bytes int64, forceBytes bool) string { + if bytes == 0 { + return "" + } + if forceBytes { return fmt.Sprintf("%v B", bytes) } diff --git a/drive/types.go b/drive/types.go index d3f0969..6fa2f3a 100644 --- a/drive/types.go +++ b/drive/types.go @@ -52,6 +52,12 @@ type FileInfoArgs struct { SizeInBytes bool } +type MkdirArgs struct { + Name string + Parent string + Share bool +} + type PrintFileListArgs struct { Files []*drive.File NameWidth int @@ -162,7 +162,7 @@ func main() { &cli.Handler{ Pattern: "[global options] mkdir [options] <name>", Description: "Create directory", - Callback: handler, + Callback: mkdirHandler, Flags: cli.Flags{ "global options": globalFlags, "options": []cli.Flag{ diff --git a/handlers.go b/handlers.go index b09159f..64e4fcd 100644 --- a/handlers.go +++ b/handlers.go @@ -15,9 +15,8 @@ const TokenFilename = "token_v2.json" func listHandler(ctx cli.Context) { args := ctx.Args() - gdrive := newDrive(args) - gdrive.List(drive.ListFilesArgs{ + newDrive(args).List(drive.ListFilesArgs{ MaxFiles: args.Int64("maxFiles"), NameWidth: args.Int64("nameWidth"), Query: args.String("query"), @@ -28,9 +27,8 @@ func listHandler(ctx cli.Context) { func downloadHandler(ctx cli.Context) { args := ctx.Args() - gdrive := newDrive(args) - gdrive.Download(drive.DownloadFileArgs{ + newDrive(args).Download(drive.DownloadFileArgs{ Id: args.String("id"), Force: args.Bool("force"), Stdout: args.Bool("stdout"), @@ -40,9 +38,8 @@ func downloadHandler(ctx cli.Context) { func uploadHandler(ctx cli.Context) { args := ctx.Args() - gdrive := newDrive(args) - gdrive.Upload(drive.UploadFileArgs{ + newDrive(args).Upload(drive.UploadFileArgs{ Path: args.String("path"), Name: args.String("name"), Parent: args.String("parent"), @@ -55,14 +52,23 @@ func uploadHandler(ctx cli.Context) { func infoHandler(ctx cli.Context) { args := ctx.Args() - gdrive := newDrive(args) - gdrive.Info(drive.FileInfoArgs{ + newDrive(args).Info(drive.FileInfoArgs{ Id: args.String("id"), SizeInBytes: args.Bool("sizeInBytes"), }) } +func mkdirHandler(ctx cli.Context) { + args := ctx.Args() + + newDrive(args).Mkdir(drive.MkdirArgs{ + Name: args.String("name"), + Parent: args.String("parent"), + Share: args.Bool("share"), + }) +} + func deleteHandler(ctx cli.Context) { fmt.Println("Deleting...") } |
