Skip to content

Commit c0a7775

Browse files
committed
Fixed linting issues
1 parent eb5c4d1 commit c0a7775

File tree

3 files changed

+49
-21
lines changed

3 files changed

+49
-21
lines changed

internal/util/tree/tree.go

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ func PrintObjectTree(tree *tree.ObjectTree, w io.Writer) {
123123
addObjectRow("", tbl, tree, tree.GetRoot())
124124

125125
// Prints the output table
126-
tbl.Render()
126+
if err := tbl.Render(); err != nil {
127+
fmt.Printf("Error rendering table: %v", err)
128+
os.Exit(1)
129+
}
127130
}
128131

129132
// PrintObjectTreeV1Beta1 prints the cluster status to stdout.
@@ -136,7 +139,10 @@ func PrintObjectTreeV1Beta1(tree *tree.ObjectTree) {
136139
addObjectRowV1Beta1("", tbl, tree, tree.GetRoot())
137140

138141
// Prints the output table
139-
tbl.Render()
142+
if err := tbl.Render(); err != nil {
143+
fmt.Printf("Error rendering table: %v", err)
144+
os.Exit(1)
145+
}
140146
}
141147

142148
// addObjectRow add a row for a given object, and recursively for all the object's children.
@@ -179,7 +185,7 @@ func addObjectRow(prefix string, tbl *tablewriter.Table, objectTree *tree.Object
179185
if len(msg) >= 1 {
180186
msg0 = msg[0]
181187
}
182-
tbl.Append([]string{
188+
if err := tbl.Append([]string{
183189
fmt.Sprintf("%s%s", gray.Sprint(prefix), name),
184190
rowDescriptor.replicas,
185191
rowDescriptor.availableCounters,
@@ -188,11 +194,14 @@ func addObjectRow(prefix string, tbl *tablewriter.Table, objectTree *tree.Object
188194
rowDescriptor.status,
189195
rowDescriptor.reason,
190196
rowDescriptor.age,
191-
msg0})
197+
msg0}); err != nil {
198+
fmt.Printf("Error appending row: %v", err)
199+
os.Exit(1)
200+
}
192201

193202
multilinePrefix := getRootMultiLineObjectPrefix(obj, objectTree)
194203
for _, m := range msg[1:] {
195-
tbl.Append([]string{
204+
if err := tbl.Append([]string{
196205
gray.Sprint(multilinePrefix),
197206
"",
198207
"",
@@ -201,7 +210,10 @@ func addObjectRow(prefix string, tbl *tablewriter.Table, objectTree *tree.Object
201210
"",
202211
"",
203212
"",
204-
m})
213+
m}); err != nil {
214+
fmt.Printf("Error appending row: %v", err)
215+
os.Exit(1)
216+
}
205217
}
206218

207219
// If it is required to show all the conditions for the object, add a row for each object's conditions.
@@ -259,13 +271,16 @@ func addObjectRowV1Beta1(prefix string, tbl *tablewriter.Table, objectTree *tree
259271
// Add the row representing the object that includes
260272
// - The row name with the tree view prefix.
261273
// - The object's ready condition.
262-
tbl.Append([]string{
274+
if err := tbl.Append([]string{
263275
fmt.Sprintf("%s%s", gray.Sprint(prefix), name),
264276
readyDescriptor.readyColor.Sprint(readyDescriptor.status),
265277
readyDescriptor.readyColor.Sprint(readyDescriptor.severity),
266278
readyDescriptor.readyColor.Sprint(readyDescriptor.reason),
267279
readyDescriptor.age,
268-
readyDescriptor.message})
280+
readyDescriptor.message}); err != nil {
281+
fmt.Printf("Error appending row: %v", err)
282+
os.Exit(1)
283+
}
269284

270285
// If it is required to show all the conditions for the object, add a row for each object's conditions.
271286
if tree.IsShowConditionsObject(obj) {
@@ -330,7 +345,7 @@ func addOtherConditions(prefix string, tbl *tablewriter.Table, objectTree *tree.
330345
if len(msg) >= 1 {
331346
msg0 = msg[0]
332347
}
333-
tbl.Append([]string{
348+
if err := tbl.Append([]string{
334349
fmt.Sprintf("%s%s", gray.Sprint(childPrefix), cyan.Sprint(condition.Type)),
335350
"",
336351
"",
@@ -339,10 +354,13 @@ func addOtherConditions(prefix string, tbl *tablewriter.Table, objectTree *tree.
339354
c.Sprint(status),
340355
reason,
341356
age,
342-
msg0})
357+
msg0}); err != nil {
358+
fmt.Printf("Error appending row: %v", err)
359+
os.Exit(1)
360+
}
343361

344362
for _, m := range msg[1:] {
345-
tbl.Append([]string{
363+
if err := tbl.Append([]string{
346364
gray.Sprint(getMultilineConditionPrefix(childPrefix)),
347365
"",
348366
"",
@@ -351,7 +369,10 @@ func addOtherConditions(prefix string, tbl *tablewriter.Table, objectTree *tree.
351369
"",
352370
"",
353371
"",
354-
m})
372+
m}); err != nil {
373+
fmt.Printf("Error appending row: %v", err)
374+
os.Exit(1)
375+
}
355376
}
356377
}
357378
}
@@ -373,13 +394,16 @@ func addOtherConditionsV1Beta1(prefix string, tbl *tablewriter.Table, objectTree
373394
otherCondition := otherConditions[i]
374395
otherDescriptor := newV1Beta1ConditionDescriptor(otherCondition)
375396
otherConditionPrefix := getChildPrefix(prefix+childrenPipe+filler, i, len(otherConditions))
376-
tbl.Append([]string{
397+
if err := tbl.Append([]string{
377398
fmt.Sprintf("%s%s", gray.Sprint(otherConditionPrefix), cyan.Sprint(otherCondition.Type)),
378399
otherDescriptor.readyColor.Sprint(otherDescriptor.status),
379400
otherDescriptor.readyColor.Sprint(otherDescriptor.severity),
380401
otherDescriptor.readyColor.Sprint(otherDescriptor.reason),
381402
otherDescriptor.age,
382-
otherDescriptor.message})
403+
otherDescriptor.message}); err != nil {
404+
fmt.Printf("Error appending row: %v", err)
405+
os.Exit(1)
406+
}
383407
}
384408
}
385409

internal/util/tree/tree_test.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ package tree
1919
import (
2020
"bytes"
2121
"fmt"
22+
"os"
2223
"strings"
2324
"testing"
2425

2526
"github.com/fatih/color"
26-
// "github.com/olekukonko/tablewriter"
27-
// "github.com/olekukonko/tablewriter/tw".
2827
. "github.com/onsi/gomega"
2928
gtype "github.com/onsi/gomega/types"
3029
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -284,8 +283,10 @@ func Test_V1Beta1TreePrefix(t *testing.T) {
284283

285284
// Add row for the root object, the cluster, and recursively for all the nodes representing the cluster status.
286285
addObjectRowV1Beta1("", tbl, tt.objectTree, tt.objectTree.GetRoot())
287-
tbl.Render()
288-
286+
if err := tbl.Render(); err != nil {
287+
fmt.Printf("Error rendering table: %v", err)
288+
os.Exit(1)
289+
}
289290
// Compare the output with the expected prefix.
290291
// We only check whether the output starts with the expected prefix,
291292
// meaning expectPrefix does not contain the full expected output.
@@ -512,8 +513,11 @@ func Test_TreePrefix(t *testing.T) {
512513

513514
// Add row for the root object, the cluster, and recursively for all the nodes representing the cluster status.
514515
addObjectRow("", tbl, tt.objectTree, tt.objectTree.GetRoot())
515-
tbl.Render()
516516

517+
if err := tbl.Render(); err != nil {
518+
fmt.Printf("Error rendering table: %v", err)
519+
os.Exit(1)
520+
}
517521
// Remove empty lines from the output. We need this because v1beta2 adds lines at the beginning and end.
518522
outputString := strings.TrimSpace(output.String())
519523

test/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoG
259259
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
260260
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
261261
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
262-
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
263-
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
262+
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
263+
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
264264
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
265265
github.com/sagikazarmark/locafero v0.11.0 h1:1iurJgmM9G3PA/I+wWYIOw/5SyBtxapeHDcg+AAIFXc=
266266
github.com/sagikazarmark/locafero v0.11.0/go.mod h1:nVIGvgyzw595SUSUE6tvCp3YYTeHs15MvlmU87WwIik=

0 commit comments

Comments
 (0)