forked from plouc/go-gitlab-client
/
environments.go
53 lines (49 loc) · 1.38 KB
/
environments.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
package output
import (
"fmt"
"github.com/fatih/color"
"github.com/olekukonko/tablewriter"
"github.com/edison-moreland/go-gitlab-client/v3/gitlab"
"io"
)
func Environments(w io.Writer, format string, collection *gitlab.EnvironmentCollection) {
if format == "json" {
collection.RenderJson(w)
} else if format == "yaml" {
collection.RenderYaml(w)
} else {
fmt.Fprintln(w, "")
table := tablewriter.NewWriter(w)
table.SetHeader([]string{
"Id",
"Name",
"Slug",
"External URL",
})
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
for _, environment := range collection.Items {
table.Append([]string{
fmt.Sprintf("%d", environment.Id),
environment.Name,
environment.Slug,
environment.ExternalUrl,
})
}
table.Render()
fmt.Fprintln(w, "")
}
}
func Environment(w io.Writer, format string, environment *gitlab.Environment) {
if format == "json" {
environment.RenderJson(w)
} else if format == "yaml" {
environment.RenderYaml(w)
} else {
fmt.Fprintln(w, "")
fmt.Fprintf(w, " Id %s\n", color.YellowString("%d", environment.Id))
fmt.Fprintf(w, " Name %s\n", color.YellowString(environment.Name))
fmt.Fprintf(w, " Slug %s\n", color.YellowString(environment.Slug))
fmt.Fprintf(w, " External URL %s\n", color.YellowString(environment.ExternalUrl))
fmt.Fprintln(w, "")
}
}