Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Dont download data if file is skipped #347

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Add rename command to fix #225
  • Loading branch information
jackschmidt authored and Elbandi committed Jan 22, 2021
commit 31678d321573d59fc2080abb49e9e2f258ede61a
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ gdrive [global] share [options] <fileId> Share file or dir
gdrive [global] share list <fileId> List files permissions
gdrive [global] share revoke <fileId> <permissionId> Revoke permission
gdrive [global] delete [options] <fileId> Delete file or directory
gdrive [global] rename <fileId> <newName> Rename file or directory
gdrive [global] sync list [options] List all syncable directories on drive
gdrive [global] sync content [options] <fileId> List content of syncable directory
gdrive [global] sync download [options] <fileId> <path> Sync drive directory to local directory
Expand Down Expand Up @@ -347,6 +348,17 @@ options:
-r, --recursive Delete directory and all it's content
```

#### Rename file or directory
```
Rename file or directory
gdrive [global] rename <fileId> <newName>

global:
-c, --config <configDir> Application path, default: /Users/jack/.gdrive
--refresh-token <refreshToken> Oauth refresh token used to get access token (for advanced users)
--access-token <accessToken> Oauth access token, only recommended for short-lived requests because of short lifetime (for advanced users)
```

#### List all syncable directories on drive
```
gdrive [global] sync list [options]
Expand Down
28 changes: 28 additions & 0 deletions drive/rename.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package drive

import (
"fmt"
"io"
"google.golang.org/api/drive/v3"
)

type RenameArgs struct {
Out io.Writer
Id string
NewName string
}

func (self *Drive) Rename(args RenameArgs) error {
f, err := self.service.Files.Get(args.Id).Fields("name", "mimeType").Do()
if err != nil {
return fmt.Errorf("Failed to get file: %s", err)
}

f2, err := self.service.Files.Update(args.Id,&drive.File{Name:args.NewName}).Do()
if err != nil {
return fmt.Errorf("Failed to rename file: %s", err)
}

fmt.Fprintf(args.Out, "Renamed '%s' -> '%s'\n", f.Name, f2.Name)
return nil
}
8 changes: 8 additions & 0 deletions gdrive.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,14 @@ func main() {
),
},
},
&cli.Handler{
Pattern: "[global] rename <fileId> <newName>",
Description: "Rename file or directory",
Callback: renameHandler,
FlagGroups: cli.FlagGroups{
cli.NewFlagGroup("global", globalFlags...),
},
},
&cli.Handler{
Pattern: "[global] sync list [options]",
Description: "List all syncable directories on drive",
Expand Down
10 changes: 10 additions & 0 deletions handlers_drive.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,16 @@ func deleteHandler(ctx cli.Context) {
checkErr(err)
}

func renameHandler(ctx cli.Context) {
args := ctx.Args()
err := newDrive(args).Rename(drive.RenameArgs{
Out: os.Stdout,
Id: args.String("fileId"),
NewName: args.String("newName"),
})
checkErr(err)
}

func listSyncHandler(ctx cli.Context) {
args := ctx.Args()
err := newDrive(args).ListSync(drive.ListSyncArgs{
Expand Down