aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetter Rasmussen2016-01-17 11:21:47 +0100
committerPetter Rasmussen2016-01-17 11:21:47 +0100
commit9e3c856daf642e914891b64d43ba3e579093a8dc (patch)
tree2ac9ed51f6b79caf9388f6a42be7b2f64c83fd55
parent2726ba76fe0f6b1e1f3ea9a45465e9d0ec3a5758 (diff)
downloadgdrive-9e3c856daf642e914891b64d43ba3e579093a8dc.tar.bz2
Respect configDir flag
-rw-r--r--gdrive.go5
-rw-r--r--handlers.go20
-rw-r--r--util.go4
3 files changed, 15 insertions, 14 deletions
diff --git a/gdrive.go b/gdrive.go
index f5f7edb..a4a5049 100644
--- a/gdrive.go
+++ b/gdrive.go
@@ -9,15 +9,10 @@ import (
const Name = "gdrive"
const Version = "2.0.0"
-const ClientId = "367116221053-7n0vf5akeru7on6o2fjinrecpdoe99eg.apps.googleusercontent.com"
-const ClientSecret = "1qsNodXNaWq1mQuBjUjmvhoO"
-
const DefaultMaxFiles = 30
const DefaultNameWidth = 40
const DefaultQuery = "trashed = false and 'me' in owners"
-
var DefaultConfigDir = GetDefaultConfigDir()
-var DefaultTokenFilePath = GetDefaultTokenFilePath()
func main() {
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())
}
diff --git a/util.go b/util.go
index f5cec71..7f43bd2 100644
--- a/util.go
+++ b/util.go
@@ -11,8 +11,8 @@ func GetDefaultConfigDir() string {
return filepath.Join(Homedir(), ".gdrive")
}
-func GetDefaultTokenFilePath() string {
- return filepath.Join(GetDefaultConfigDir(), "token_v2.json")
+func ConfigFilePath(basePath, name string) string {
+ return filepath.Join(basePath, name)
}
func Homedir() string {