Skip to content

Commit

Permalink
Add --absolute flag to show abs path to file
Browse files Browse the repository at this point in the history
  • Loading branch information
prasmussen committed Feb 21, 2016
1 parent 9ee98bc commit f20a7f8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
15 changes: 14 additions & 1 deletion drive/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions gdrive.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
1 change: 1 addition & 0 deletions handlers_drive.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit f20a7f8

Please sign in to comment.