diff options
| author | Petter Rasmussen | 2016-01-17 11:21:47 +0100 |
|---|---|---|
| committer | Petter Rasmussen | 2016-01-17 11:21:47 +0100 |
| commit | 9e3c856daf642e914891b64d43ba3e579093a8dc (patch) | |
| tree | 2ac9ed51f6b79caf9388f6a42be7b2f64c83fd55 /handlers.go | |
| parent | 2726ba76fe0f6b1e1f3ea9a45465e9d0ec3a5758 (diff) | |
| download | gdrive-9e3c856daf642e914891b64d43ba3e579093a8dc.tar.bz2 | |
Respect configDir flag
Diffstat (limited to 'handlers.go')
| -rw-r--r-- | handlers.go | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/handlers.go b/handlers.go index 59607da..b09159f 100644 --- a/handlers.go +++ b/handlers.go @@ -8,9 +8,14 @@ import ( "./drive" ) +const ClientId = "367116221053-7n0vf5akeru7on6o2fjinrecpdoe99eg.apps.googleusercontent.com" +const ClientSecret = "1qsNodXNaWq1mQuBjUjmvhoO" +const TokenFilename = "token_v2.json" + + func listHandler(ctx cli.Context) { args := ctx.Args() - gdrive := newDrive() + gdrive := newDrive(args) gdrive.List(drive.ListFilesArgs{ MaxFiles: args.Int64("maxFiles"), @@ -23,7 +28,7 @@ func listHandler(ctx cli.Context) { func downloadHandler(ctx cli.Context) { args := ctx.Args() - gdrive := newDrive() + gdrive := newDrive(args) gdrive.Download(drive.DownloadFileArgs{ Id: args.String("id"), @@ -35,7 +40,7 @@ func downloadHandler(ctx cli.Context) { func uploadHandler(ctx cli.Context) { args := ctx.Args() - gdrive := newDrive() + gdrive := newDrive(args) gdrive.Upload(drive.UploadFileArgs{ Path: args.String("path"), @@ -50,7 +55,7 @@ func uploadHandler(ctx cli.Context) { func infoHandler(ctx cli.Context) { args := ctx.Args() - gdrive := newDrive() + gdrive := newDrive(args) gdrive.Info(drive.FileInfoArgs{ Id: args.String("id"), @@ -100,9 +105,10 @@ func printCommandHelp(ctx cli.Context) { } } -// TODO: take app path as arg -func newDrive() *drive.Drive { - oauth, err := client.NewOauthClient(ClientId, ClientSecret, DefaultTokenFilePath, authCodePrompt) +func newDrive(args cli.Arguments) *drive.Drive { + configDir := args.String("configDir") + tokenPath := ConfigFilePath(configDir, TokenFilename) + oauth, err := client.NewOauthClient(ClientId, ClientSecret, tokenPath, authCodePrompt) if err != nil { ExitF("Failed getting oauth client: %s", err.Error()) } |
