forked from pachyderm/pachyderm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pretty.go
117 lines (104 loc) · 2.56 KB
/
pretty.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package pretty
import (
"fmt"
"io"
"time"
"go.pedge.io/proto/time"
"github.com/docker/go-units"
"github.com/pachyderm/pachyderm/src/client/pfs"
)
func PrintRepoHeader(w io.Writer) {
fmt.Fprint(w, "NAME\tCREATED\tSIZE\t\n")
}
func PrintRepoInfo(w io.Writer, repoInfo *pfs.RepoInfo) {
fmt.Fprintf(w, "%s\t", repoInfo.Repo.Name)
fmt.Fprintf(
w,
"%s ago\t", units.HumanDuration(
time.Since(
prototime.TimestampToTime(
repoInfo.Created,
),
),
),
)
fmt.Fprintf(w, "%s\t\n", units.BytesSize(float64(repoInfo.SizeBytes)))
}
func PrintCommitInfoHeader(w io.Writer) {
fmt.Fprint(w, "BRANCH\tID\tPARENT\tSTARTED\tFINISHED\tSIZE\t\n")
}
func PrintCommitInfo(w io.Writer, commitInfo *pfs.CommitInfo) {
fmt.Fprintf(w, "%s\t", commitInfo.Branch)
fmt.Fprintf(w, "%s\t", commitInfo.Commit.ID)
if commitInfo.ParentCommit != nil {
fmt.Fprintf(w, "%s\t", commitInfo.ParentCommit.ID)
} else {
fmt.Fprint(w, "<none>\t")
}
fmt.Fprintf(
w,
"%s ago\t", units.HumanDuration(
time.Since(
prototime.TimestampToTime(
commitInfo.Started,
),
),
),
)
finished := "\t"
if commitInfo.Finished != nil {
finished = fmt.Sprintf("%s ago\t", units.HumanDuration(
time.Since(
prototime.TimestampToTime(
commitInfo.Finished,
),
),
))
}
fmt.Fprintf(w, finished)
fmt.Fprintf(w, "%s\t\n", units.BytesSize(float64(commitInfo.SizeBytes)))
}
func PrintFileInfoHeader(w io.Writer) {
fmt.Fprint(w, "NAME\tTYPE\tMODIFIED\tLAST_COMMIT_MODIFIED\tSIZE\t\n")
}
func PrintFileInfo(w io.Writer, fileInfo *pfs.FileInfo) {
fmt.Fprintf(w, "%s\t", fileInfo.File.Path)
if fileInfo.FileType == pfs.FileType_FILE_TYPE_REGULAR {
fmt.Fprint(w, "file\t")
} else {
fmt.Fprint(w, "dir\t")
}
fmt.Fprintf(
w,
"%s ago\t", units.HumanDuration(
time.Since(
prototime.TimestampToTime(
fileInfo.Modified,
),
),
),
)
fmt.Fprint(w, "-\t")
fmt.Fprintf(w, "%s\t\n", units.BytesSize(float64(fileInfo.SizeBytes)))
}
func PrintBlockInfoHeader(w io.Writer) {
fmt.Fprintf(w, "HASH\tCREATED\tSIZE\t\n")
}
func PrintBlockInfo(w io.Writer, blockInfo *pfs.BlockInfo) {
fmt.Fprintf(w, "%s\t", blockInfo.Block.Hash)
fmt.Fprintf(
w,
"%s ago\t", units.HumanDuration(
time.Since(
prototime.TimestampToTime(
blockInfo.Created,
),
),
),
)
fmt.Fprintf(w, "%s\t\n", units.BytesSize(float64(blockInfo.SizeBytes)))
}
type uint64Slice []uint64
func (s uint64Slice) Len() int { return len(s) }
func (s uint64Slice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s uint64Slice) Less(i, j int) bool { return s[i] < s[j] }