forked from prasmussen/gdrive
-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
revision_list.go
63 lines (52 loc) · 1.32 KB
/
revision_list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package drive
import (
"fmt"
"io"
"text/tabwriter"
"google.golang.org/api/drive/v3"
)
type ListRevisionsArgs struct {
Out io.Writer
Id string
NameWidth int64
SkipHeader bool
SizeInBytes bool
}
func (self *Drive) ListRevisions(args ListRevisionsArgs) (err error) {
revList, err := self.service.Revisions.List(args.Id).Fields("revisions(id,keepForever,size,modifiedTime,originalFilename)").Do()
if err != nil {
return fmt.Errorf("Failed listing revisions: %s", err)
}
PrintRevisionList(PrintRevisionListArgs{
Out: args.Out,
Revisions: revList.Revisions,
NameWidth: int(args.NameWidth),
SkipHeader: args.SkipHeader,
SizeInBytes: args.SizeInBytes,
})
return
}
type PrintRevisionListArgs struct {
Out io.Writer
Revisions []*drive.Revision
NameWidth int
SkipHeader bool
SizeInBytes bool
}
func PrintRevisionList(args PrintRevisionListArgs) {
w := new(tabwriter.Writer)
w.Init(args.Out, 0, 0, 3, ' ', 0)
if !args.SkipHeader {
fmt.Fprintln(w, "Id\tName\tSize\tModified\tKeepForever")
}
for _, rev := range args.Revisions {
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n",
rev.Id,
truncateString(rev.OriginalFilename, args.NameWidth),
formatSize(rev.Size, args.SizeInBytes),
formatDatetime(rev.ModifiedTime),
formatBool(rev.KeepForever),
)
}
w.Flush()
}