-
Notifications
You must be signed in to change notification settings - Fork 10
/
show.go
200 lines (158 loc) · 5.5 KB
/
show.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package command
import (
"fmt"
"os"
"strconv"
"strings"
"github.com/spf13/cobra"
"github.com/simplesurance/baur/format"
"github.com/simplesurance/baur/format/table"
"github.com/simplesurance/baur/log"
"github.com/simplesurance/baur/storage"
)
const showLongHelp = `
Show information about an application or a build.
If the name or the path to an application directory is passed,
application information are shown.
If a numeric build ID is passed, information about the build are shown.
`
const showExamples = `
baur show calc show information about the calc application
baur show ui/shop show information about the app in the ui/shop directory
baur show 512 show information about build 512
`
var showCmd = &cobra.Command{
Use: "show APP|APP-PATH|BUILD-ID",
Short: "show information about apps or builds",
Args: cobra.ExactArgs(1),
Run: show,
Long: strings.TrimSpace(showLongHelp),
Example: strings.TrimSpace(showExamples),
}
func init() {
rootCmd.AddCommand(showCmd)
}
func show(cmd *cobra.Command, args []string) {
buildID, err := strconv.Atoi(args[0])
if err == nil {
showBuild(buildID)
} else {
showApp(args[0])
}
}
func showApp(arg string) {
var formatter format.Formatter
repo := MustFindRepository()
app := mustArgToApp(repo, arg)
formatter = table.New(nil, os.Stdout)
mustWriteRow(formatter, []interface{}{underline("General:")})
mustWriteRow(formatter, []interface{}{"", "Name:", highlight(app.Name)})
mustWriteRow(formatter, []interface{}{"", "Path:", highlight(app.RelPath)})
mustWriteRow(formatter, []interface{}{"", "Build Command:", highlight(app.BuildCmd)})
if len(app.Outputs) != 0 {
mustWriteRow(formatter, []interface{}{})
mustWriteRow(formatter, []interface{}{underline("Outputs:")})
for i, art := range app.Outputs {
mustWriteRow(formatter, []interface{}{"", "Type:", highlight(art.Type())})
mustWriteRow(formatter, []interface{}{"", "Local:", highlight(art.String())})
mustWriteRow(formatter, []interface{}{"", "Remote:", highlight(art.UploadDestination())})
if i+1 < len(app.Outputs) {
mustWriteRow(formatter, []interface{}{})
}
}
}
if app.HasBuildInputs() {
var printNewLine bool
mustWriteRow(formatter, []interface{}{})
mustWriteRow(formatter, []interface{}{underline("Inputs:")})
for _, bi := range app.UnresolvedInputs {
if len(bi.Files.Paths) > 0 {
if printNewLine {
mustWriteRow(formatter, []interface{}{})
}
mustWriteRow(formatter, []interface{}{"", "Type:", highlight("File")})
mustWriteRow(formatter, []interface{}{"",
"Paths:", highlight(strings.Join(bi.Files.Paths, ", ")),
})
printNewLine = true
}
if len(bi.GitFiles.Paths) > 0 {
if printNewLine {
mustWriteRow(formatter, []interface{}{})
}
mustWriteRow(formatter, []interface{}{"", "Type:", highlight("GitFile")})
mustWriteRow(formatter, []interface{}{"",
"Paths:", highlight(strings.Join(bi.GitFiles.Paths, ", "))})
printNewLine = true
}
if len(bi.GolangSources.Paths) > 0 {
if printNewLine {
mustWriteRow(formatter, []interface{}{})
}
mustWriteRow(formatter, []interface{}{"", "Type:", highlight("GolangSources")})
mustWriteRow(formatter, []interface{}{"",
"Paths:", highlight(strings.Join(bi.GolangSources.Paths, ", "))})
mustWriteRow(formatter, []interface{}{"",
"Environment:", highlight(strings.Join(bi.GolangSources.Environment, ", "))})
printNewLine = true
}
}
}
if err := formatter.Flush(); err != nil {
log.Fatalln(err)
}
}
func showBuild(buildID int) {
var formatter format.Formatter
repo := MustFindRepository()
storageClt := MustGetPostgresClt(repo)
build, err := storageClt.GetBuildWithoutInputsOutputs(buildID)
if err != nil {
if err == storage.ErrNotExist {
log.Fatalf("build with id %d does not exist\n", buildID)
}
log.Fatalln(err)
}
build.Outputs, err = storageClt.GetBuildOutputs(build.ID)
if err != nil {
log.Fatalln(err)
}
formatter = table.New(nil, os.Stdout)
mustWriteRow(formatter, []interface{}{underline("General:")})
mustWriteRow(formatter, []interface{}{"", "Name:", highlight(build.Application.Name)})
mustWriteRow(formatter, []interface{}{"", "ID:", highlight(build.ID)})
mustWriteRow(formatter, []interface{}{"", "Started At:", highlight(build.StartTimeStamp)})
mustWriteRow(formatter, []interface{}{
"",
"Build Duration:",
highlight(fmt.Sprintf("%.2f s", build.StopTimeStamp.Sub(build.StartTimeStamp).Seconds())),
})
mustWriteRow(formatter, []interface{}{"", "Git Commit:", highlight(vcsStr(&build.VCSState))})
mustWriteRow(formatter, []interface{}{"", "Total Input Digest:", highlight(build.TotalInputDigest)})
if len(build.Outputs) > 0 {
mustWriteRow(formatter, []interface{}{})
mustWriteRow(formatter, []interface{}{underline("Outputs:")})
}
for i, o := range build.Outputs {
mustWriteRow(formatter, []interface{}{"", "URI:", highlight(o.Upload.URI)})
mustWriteRow(formatter, []interface{}{"", "Digest:", highlight(o.Digest)})
mustWriteRow(formatter, []interface{}{
"",
"Size:",
highlight(bytesToMib(int(o.SizeBytes)) + " MiB"),
})
mustWriteRow(formatter, []interface{}{
"",
"Upload Duration:",
highlight(durationToStrSeconds(o.Upload.UploadDuration) + " s"),
})
mustWriteRow(formatter, []interface{}{"", "Type:", highlight(o.Type)})
mustWriteRow(formatter, []interface{}{"", "Upload Method:", highlight(o.Upload.Method)})
if i+1 < len(build.Outputs) {
mustWriteRow(formatter, []interface{}{})
}
}
if err := formatter.Flush(); err != nil {
log.Fatalln(err)
}
}