From f20a7f8125d3250eeea106860009b44dca9513dd Mon Sep 17 00:00:00 2001 From: Petter Rasmussen Date: Sun, 21 Feb 2016 16:15:11 +0100 Subject: [PATCH] Add --absolute flag to show abs path to file --- drive/list.go | 15 ++++++++++++++- gdrive.go | 6 ++++++ handlers_drive.go | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/drive/list.go b/drive/list.go index e6365852..73fdea51 100644 --- a/drive/list.go +++ b/drive/list.go @@ -17,12 +17,13 @@ type ListFilesArgs struct { SortOrder string SkipHeader bool SizeInBytes bool + AbsPath bool } func (self *Drive) List(args ListFilesArgs) (err error) { listArgs := listAllFilesArgs{ query: args.Query, - fields: []googleapi.Field{"nextPageToken", "files(id,name,md5Checksum,mimeType,size,createdTime)"}, + fields: []googleapi.Field{"nextPageToken", "files(id,name,md5Checksum,mimeType,size,createdTime,parents)"}, sortOrder: args.SortOrder, maxFiles: args.MaxFiles, } @@ -31,6 +32,18 @@ func (self *Drive) List(args ListFilesArgs) (err error) { return fmt.Errorf("Failed to list files: %s", err) } + pathfinder := self.newPathfinder() + + if args.AbsPath { + // Replace name with absolute path + for _, f := range files { + f.Name, err = pathfinder.absPath(f) + if err != nil { + return err + } + } + } + PrintFileList(PrintFileListArgs{ Out: args.Out, Files: files, diff --git a/gdrive.go b/gdrive.go index d0a8c095..d9181c63 100644 --- a/gdrive.go +++ b/gdrive.go @@ -71,6 +71,12 @@ func main() { Description: fmt.Sprintf("Width of name column, default: %d, minimum: 9, use 0 for full width", DefaultNameWidth), DefaultValue: DefaultNameWidth, }, + cli.BoolFlag{ + Name: "absPath", + Patterns: []string{"--absolute"}, + Description: "Show absolute path to file (will only show path from first parent)", + OmitValue: true, + }, cli.BoolFlag{ Name: "skipHeader", Patterns: []string{"--no-header"}, diff --git a/handlers_drive.go b/handlers_drive.go index 3698d0ed..05b1ca9c 100644 --- a/handlers_drive.go +++ b/handlers_drive.go @@ -28,6 +28,7 @@ func listHandler(ctx cli.Context) { SortOrder: args.String("sortOrder"), SkipHeader: args.Bool("skipHeader"), SizeInBytes: args.Bool("sizeInBytes"), + AbsPath: args.Bool("absPath"), }) checkErr(err) }