-
Notifications
You must be signed in to change notification settings - Fork 88
/
versions.go
41 lines (35 loc) · 1006 Bytes
/
versions.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
package print
import (
"encoding/json"
"fmt"
"time"
)
type AppVersionResponse struct {
VersionLabel string `json:"versionLabel"`
Sequence int64 `json:"sequence"`
CreatedOn time.Time `json:"createdOn"`
Status string `json:"status"`
DeployedAt *time.Time `json:"deployedAt"`
Source string `json:"source"`
}
func Versions(versions []AppVersionResponse, format string) {
switch format {
case "json":
printVersionsJSON(versions)
default:
printVersionsTable(versions)
}
}
func printVersionsJSON(versions []AppVersionResponse) {
str, _ := json.MarshalIndent(versions, "", " ")
fmt.Println(string(str))
}
func printVersionsTable(versions []AppVersionResponse) {
w := NewTabWriter()
defer w.Flush()
fmtColumns := "%s\t%v\t%s\t%s\n"
fmt.Fprintf(w, fmtColumns, "VERSION", "SEQUENCE", "STATUS", "SOURCE")
for _, version := range versions {
fmt.Fprintf(w, fmtColumns, version.VersionLabel, version.Sequence, version.Status, version.Source)
}
}