forked from plouc/go-gitlab-client
/
variables.go
55 lines (49 loc) · 1.38 KB
/
variables.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
package output
import (
"fmt"
"github.com/fatih/color"
"github.com/olekukonko/tablewriter"
"github.com/plouc/go-gitlab-client/gitlab"
"io"
)
func Variables(w io.Writer, format string, collection *gitlab.VariableCollection) {
if format == "json" {
collection.RenderJson(w)
} else if format == "yaml" {
collection.RenderYaml(w)
} else {
fmt.Fprintln(w, "")
table := tablewriter.NewWriter(w)
table.SetHeader([]string{
"Key",
"Value",
"Protected",
"Environment scope",
})
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
for _, variable := range collection.Items {
table.Append([]string{
variable.Key,
variable.Value,
fmt.Sprintf("%t", variable.Protected),
variable.EnvironmentScope,
})
}
table.Render()
fmt.Fprintln(w, "")
}
}
func Variable(w io.Writer, format string, variable *gitlab.Variable) {
if format == "json" {
variable.RenderJson(w)
} else if format == "yaml" {
variable.RenderYaml(w)
} else {
fmt.Fprintln(w, "")
fmt.Fprintf(w, " Key %s\n", color.YellowString(variable.Key))
fmt.Fprintf(w, " Value %s\n", color.YellowString(variable.Value))
fmt.Fprintf(w, " Protected %s\n", color.YellowString("%t", variable.Protected))
fmt.Fprintf(w, " EnvironmentScope %s\n", color.YellowString(variable.EnvironmentScope))
fmt.Fprintln(w, "")
}
}