"Fossies" - the Fresh Open Source Software Archive 
Member "gdrive-2.1.1/drive/revision_list.go" (28 May 2021, 1351 Bytes) of package /linux/misc/gdrive-2.1.1.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Go source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 package drive
2
3 import (
4 "fmt"
5 "google.golang.org/api/drive/v3"
6 "io"
7 "text/tabwriter"
8 )
9
10 type ListRevisionsArgs struct {
11 Out io.Writer
12 Id string
13 NameWidth int64
14 SkipHeader bool
15 SizeInBytes bool
16 }
17
18 func (self *Drive) ListRevisions(args ListRevisionsArgs) (err error) {
19 revList, err := self.service.Revisions.List(args.Id).Fields("revisions(id,keepForever,size,modifiedTime,originalFilename)").Do()
20 if err != nil {
21 return fmt.Errorf("Failed listing revisions: %s", err)
22 }
23
24 PrintRevisionList(PrintRevisionListArgs{
25 Out: args.Out,
26 Revisions: revList.Revisions,
27 NameWidth: int(args.NameWidth),
28 SkipHeader: args.SkipHeader,
29 SizeInBytes: args.SizeInBytes,
30 })
31
32 return
33 }
34
35 type PrintRevisionListArgs struct {
36 Out io.Writer
37 Revisions []*drive.Revision
38 NameWidth int
39 SkipHeader bool
40 SizeInBytes bool
41 }
42
43 func PrintRevisionList(args PrintRevisionListArgs) {
44 w := new(tabwriter.Writer)
45 w.Init(args.Out, 0, 0, 3, ' ', 0)
46
47 if !args.SkipHeader {
48 fmt.Fprintln(w, "Id\tName\tSize\tModified\tKeepForever")
49 }
50
51 for _, rev := range args.Revisions {
52 fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n",
53 rev.Id,
54 truncateString(rev.OriginalFilename, args.NameWidth),
55 formatSize(rev.Size, args.SizeInBytes),
56 formatDatetime(rev.ModifiedTime),
57 formatBool(rev.KeepForever),
58 )
59 }
60
61 w.Flush()
62 }