/
groups.go
81 lines (73 loc) · 2.59 KB
/
groups.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
package output
import (
"fmt"
"github.com/fatih/color"
"github.com/olekukonko/tablewriter"
"github.com/rockwang465/gitlab-client/gitlab"
"io"
)
func Groups(w io.Writer, format string, collection *gitlab.GroupCollection) {
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",
"Path",
"Visibility",
})
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
for _, group := range collection.Items {
table.Append([]string{
fmt.Sprintf("%d", group.Id),
group.Name,
group.Path,
fmt.Sprintf("%s", group.Visibility),
})
}
table.Render()
fmt.Fprintln(w, "")
}
}
func Group(w io.Writer, format string, group *gitlab.GroupWithDetails) {
if format == "json" {
group.RenderJson(w)
} else if format == "yaml" {
group.RenderYaml(w)
} else {
fmt.Fprintln(w, "")
fmt.Fprintf(w, " Id %s\n", color.YellowString("%d", group.Id))
fmt.Fprintf(w, " Name %s\n", color.YellowString(group.Name))
fmt.Fprintf(w, " Path %s\n", color.YellowString(group.Path))
fmt.Fprintf(w, " Description %s\n", color.YellowString(group.Description))
fmt.Fprintf(w, " Visibility %s\n", color.YellowString("%s", group.Visibility))
fmt.Fprintf(w, " LfsEnabled %s\n", color.YellowString("%t", group.LfsEnabled))
fmt.Fprintf(w, " AvatarUrl %s\n", color.YellowString(group.AvatarUrl))
fmt.Fprintf(w, " WebURL %s\n", color.YellowString(group.WebURL))
fmt.Fprintf(w, " RequestAccessEnabled %s\n", color.YellowString("%t", group.RequestAccessEnabled))
fmt.Fprintf(w, " FullName %s\n", color.YellowString(group.FullName))
fmt.Fprintf(w, " FullPath %s\n", color.YellowString(group.FullPath))
fmt.Fprintf(w, " ParentId %s\n", color.YellowString("%d", group.ParentId))
fmt.Fprintln(w, " Projects")
if len(group.Projects) > 0 {
for _, project := range group.Projects {
fmt.Fprintf(w, " %-32s %s\n", color.YellowString(project.Name), fmt.Sprintf("%d", project.Id))
}
} else {
fmt.Fprintln(w, " No project")
}
fmt.Fprintln(w, " SharedProjects")
if len(group.SharedProjects) > 0 {
for _, project := range group.SharedProjects {
fmt.Fprintf(w, " %-32s %s\n", color.YellowString(project.Name), fmt.Sprintf("%d", project.Id))
}
} else {
fmt.Fprintln(w, " No shared project")
}
fmt.Fprintln(w, "")
}
}