This repository has been archived by the owner on Nov 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stylish.go
180 lines (154 loc) · 6.73 KB
/
stylish.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
package formatter
import (
"bytes"
"fmt"
"text/tabwriter"
"bunnyshell.com/sdk"
)
func stylish(data interface{}) ([]byte, error) {
var b bytes.Buffer
var err error = nil
w := tabwriter.NewWriter(&b, 1, 1, 1, ' ', tabwriter.Debug)
switch t := data.(type) {
case *sdk.PaginatedOrganizationCollection:
tabulateOrganizationCollection(w, t)
case *sdk.PaginatedProjectCollection:
tabulateProjectCollection(w, t)
case *sdk.PaginatedEnvironmentCollection:
tabulateEnvironmentCollection(w, t)
case *sdk.PaginatedComponentCollection:
tabulateComponentCollection(w, t)
case *sdk.PaginatedEventCollection:
tabulateEventCollection(w, t)
case *sdk.PaginatedEnvironmentVariableCollection:
tabulateEnvironmentVariableCollection(w, t)
case *sdk.OrganizationItem:
tabulateOrganizationItem(w, t)
case *sdk.ProjectItem:
tabulateProjectItem(w, t)
case *sdk.EnvironmentItem:
tabulateEnvironmentItem(w, t)
case *sdk.ComponentItem:
tabulateComponentItem(w, t)
case *sdk.EventItem:
tabulateEventItem(w, t)
case *sdk.EnvironmentVariableItem:
tabulateEnvironmentVariableItem(w, t)
case *sdk.ProblemGeneric:
tabulateGeneric(w, t)
default:
fmt.Fprintf(w, "JSON: ")
var jsonBytes []byte
jsonBytes, err = JsonFormatter(data)
w.Write(jsonBytes)
}
w.Flush()
return b.Bytes(), err
}
func tabulateOrganizationCollection(w *tabwriter.Writer, data *sdk.PaginatedOrganizationCollection) {
fmt.Fprintf(w, "%v\t %v\t %v\n", "OrganizationID", "Name", "Timezone")
if data.Embedded != nil {
for _, item := range data.Embedded.Item {
fmt.Fprintf(w, "%v\t %v\t %v\n", item.GetId(), item.GetName(), item.GetTimezone())
}
}
}
func tabulateOrganizationItem(w *tabwriter.Writer, item *sdk.OrganizationItem) {
fmt.Fprintf(w, "%v\t %v\n", "OrganizationID", item.GetId())
fmt.Fprintf(w, "%v\t %v\n", "Name", item.GetName())
fmt.Fprintf(w, "%v\t %v\n", "Timezone", item.GetTimezone())
fmt.Fprintf(w, "%v\t %v\n", "Projects", item.GetTotalProjects())
fmt.Fprintf(w, "%v\t %v\n", "Clusters", item.GetAvailableClusters())
fmt.Fprintf(w, "%v\t %v\n", "GitIntegrations", item.GetAvailableGitIntegration())
fmt.Fprintf(w, "%v\t %v\n", "Registries", item.GetAvailableRegistries())
}
func tabulateProjectCollection(w *tabwriter.Writer, data *sdk.PaginatedProjectCollection) {
fmt.Fprintf(w, "%v\t %v\t %v\t %v\n", "ProjectID", "OrganizationID", "Name", "Environments")
if data.Embedded != nil {
for _, item := range data.Embedded.Item {
fmt.Fprintf(w, "%v\t %v\t %v\t %v\n", item.GetId(), item.GetOrganization(), item.GetName(), item.GetTotalEnvironments())
}
}
}
func tabulateProjectItem(w *tabwriter.Writer, item *sdk.ProjectItem) {
fmt.Fprintf(w, "%v\t %v\n", "ProjectID", item.GetId())
fmt.Fprintf(w, "%v\t %v\n", "OrganizationID", item.GetOrganization())
fmt.Fprintf(w, "%v\t %v\n", "Name", item.GetName())
fmt.Fprintf(w, "%v\t %v\n", "Environments", item.GetTotalEnvironments())
}
func tabulateEnvironmentCollection(w *tabwriter.Writer, data *sdk.PaginatedEnvironmentCollection) {
fmt.Fprintf(w, "%v\t %v\t %v\t %v\t %v\t %v\n", "EnvironmentID", "ProjectID", "Name", "Namespace", "Type", "OperationStatus")
if data.Embedded != nil {
for _, item := range data.Embedded.Item {
fmt.Fprintf(w, "%v\t %v\t %v\t %v\t %v\t %v\n", item.GetId(), item.GetProject(), item.GetName(), item.GetNamespace(), item.GetType(), item.GetOperationStatus())
}
}
}
func tabulateEnvironmentItem(w *tabwriter.Writer, item *sdk.EnvironmentItem) {
fmt.Fprintf(w, "%v\t %v\n", "EnvironmentID", item.GetId())
fmt.Fprintf(w, "%v\t %v\n", "ProjectID", item.GetProject())
fmt.Fprintf(w, "%v\t %v\n", "Name", item.GetName())
fmt.Fprintf(w, "%v\t %v\n", "Namespace", item.GetNamespace())
fmt.Fprintf(w, "%v\t %v\n", "Type", item.GetType())
fmt.Fprintf(w, "%v\t %v\n", "Components", item.GetTotalComponents())
fmt.Fprintf(w, "%v\t %v\n", "OperationStatus", item.GetOperationStatus())
}
func tabulateComponentCollection(w *tabwriter.Writer, data *sdk.PaginatedComponentCollection) {
fmt.Fprintf(w, "%v\t %v\t %v\t %v\t %v\n", "ComponentID", "EnvironmentID", "Name", "OperationStatus", "ClusterStatus")
if data.Embedded != nil {
for _, item := range data.Embedded.Item {
fmt.Fprintf(w, "%v\t %v\t %v\t %v\t %v\n", item.GetId(), item.GetEnvironment(), item.GetName(), item.GetOperationStatus(), item.GetClusterStatus())
}
}
}
func tabulateComponentItem(w *tabwriter.Writer, item *sdk.ComponentItem) {
fmt.Fprintf(w, "%v\t %v\n", "ComponentID", item.GetId())
fmt.Fprintf(w, "%v\t %v\n", "EnvironmentID", item.GetEnvironment())
fmt.Fprintf(w, "%v\t %v\n", "Name", item.GetName())
fmt.Fprintf(w, "%v\t %v\n", "OperationStatus", item.GetOperationStatus())
fmt.Fprintf(w, "%v\t %v\n", "ClusterStatus", item.GetClusterStatus())
for index, url := range item.GetPublicURLs() {
if index == 0 {
fmt.Fprintf(w, "%v\t %v\n", "Public URL", url)
} else {
fmt.Fprintf(w, "\t %v\n", url)
}
}
}
func tabulateEventCollection(w *tabwriter.Writer, data *sdk.PaginatedEventCollection) {
fmt.Fprintf(w, "%v\t %v\t %v\t %v\t %v\n", "EventID", "EnvironmentID", "OrganizationID", "Type", "Status")
if data.Embedded != nil {
for _, item := range data.Embedded.Item {
fmt.Fprintf(w, "%v\t %v\t %v\t %v\t %v\n", item.GetId(), item.GetEnvironment(), item.GetOrganization(), item.GetType(), item.GetStatus())
}
}
}
func tabulateEnvironmentVariableCollection(w *tabwriter.Writer, data *sdk.PaginatedEnvironmentVariableCollection) {
fmt.Fprintf(w, "%v\t %v\t %v\t %v\n", "EnvVarID", "EnvironmentID", "OrganizationID", "Name")
if data.Embedded != nil {
for _, item := range data.Embedded.Item {
fmt.Fprintf(w, "%v\t %v\t %v\t %v\n", item.GetId(), item.GetEnvironment(), item.GetOrganization(), item.GetName())
}
}
}
func tabulateEventItem(w *tabwriter.Writer, item *sdk.EventItem) {
fmt.Fprintf(w, "%v\t %v\n", "EventID", item.GetId())
fmt.Fprintf(w, "%v\t %v\n", "EnvironmentID", item.GetEnvironment())
fmt.Fprintf(w, "%v\t %v\n", "OrganizationID", item.GetOrganization())
fmt.Fprintf(w, "%v\t %v\n", "Status", item.GetStatus())
fmt.Fprintf(w, "%v\t %v\n", "Type", item.GetType())
fmt.Fprintf(w, "%v\t %v\n", "CreatedAt", item.GetCreatedAt())
fmt.Fprintf(w, "%v\t %v\n", "UpdatedAt", item.GetUpdatedAt())
}
func tabulateEnvironmentVariableItem(w *tabwriter.Writer, item *sdk.EnvironmentVariableItem) {
fmt.Fprintf(w, "%v\t %v\n", "EnvironmentID", item.GetEnvironment())
fmt.Fprintf(w, "%v\t %v\n", "OrganizationID", item.GetOrganization())
fmt.Fprintf(w, "%v\t %v\n", "Name", item.GetName())
fmt.Fprintf(w, "%v\t %v\n", "Value", item.GetValue())
fmt.Fprintf(w, "%v\t %v\n", "Secret", item.GetSecret())
}
func tabulateGeneric(w *tabwriter.Writer, item *sdk.ProblemGeneric) {
fmt.Fprintf(w, "%v\n", "ERROR")
fmt.Fprintf(w, "%v\t %v\n", "Title", item.GetTitle())
fmt.Fprintf(w, "%v\t %v\n", "Detail", item.GetDetail())
}