Skip to content

Commit b7f4ba5

Browse files
Revert "[chore] Update output tables (#114)"
This reverts commit fe0978a.
1 parent 1181393 commit b7f4ba5

File tree

7 files changed

+106
-216
lines changed

7 files changed

+106
-216
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
github.com/docker/buildx v0.16.0
1414
github.com/enescakir/emoji v1.0.0
1515
github.com/hashicorp/go-retryablehttp v0.7.7
16-
github.com/jedib0t/go-pretty/v6 v6.6.0
16+
github.com/jedib0t/go-pretty v4.3.0+incompatible
1717
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213
1818
github.com/moby/buildkit v0.15.1
1919
github.com/project-copacetic/copacetic v0.7.1-0.20240723231147-beb8c86673a8

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,8 +1004,8 @@ github.com/jackc/puddle v1.3.0 h1:eHK/5clGOatcjX3oWGBO/MpxpbHzSwud5EWTSCI+MX0=
10041004
github.com/jackc/puddle v1.3.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
10051005
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
10061006
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
1007-
github.com/jedib0t/go-pretty/v6 v6.6.0 h1:wmZVuAcEkZRT+Aq1xXpE8IGat4vE5WXOMmBpbQqERXw=
1008-
github.com/jedib0t/go-pretty/v6 v6.6.0/go.mod h1:zbn98qrYlh95FIhwwsbIip0LYpwSG8SUOScs+v9/t0E=
1007+
github.com/jedib0t/go-pretty v4.3.0+incompatible h1:CGs8AVhEKg/n9YbUenWmNStRW2PHJzaeDodcfvRAbIo=
1008+
github.com/jedib0t/go-pretty v4.3.0+incompatible/go.mod h1:XemHduiw8R651AF9Pt4FwCTKeG3oo7hrHJAoznj9nag=
10091009
github.com/jedisct1/go-minisign v0.0.0-20230811132847-661be99b8267 h1:TMtDYDHKYY15rFihtRfck/bfFqNfvcabqvXAFQfAUpY=
10101010
github.com/jedisct1/go-minisign v0.0.0-20230811132847-661be99b8267/go.mod h1:h1nSAbGFqGVzn6Jyl1R/iCcBUHN4g+gW1u9CoBTrb9E=
10111011
github.com/jellydator/ttlcache/v3 v3.3.0 h1:BdoC9cE81qXfrxeb9eoJi9dWrdhSuwXMAnHTbnBm4Wc=

internal/output/table.go

Lines changed: 13 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package output
22

33
import (
44
"context"
5-
"fmt"
65
"log/slog"
76
"os"
87
"strings"
@@ -16,22 +15,21 @@ import (
1615
"github.com/ChristofferNissen/helmper/pkg/util/file"
1716
"github.com/ChristofferNissen/helmper/pkg/util/state"
1817
"github.com/ChristofferNissen/helmper/pkg/util/terminal"
19-
"github.com/jedib0t/go-pretty/v6/table"
18+
"github.com/jedib0t/go-pretty/table"
2019
)
2120

2221
var sc counter.SafeCounter = counter.NewSafeCounter()
2322

2423
// create a new table.writer with header and os.Stdout output mirror
25-
func newTable(title string, header table.Row) table.Writer {
24+
func newTable(row table.Row) table.Writer {
2625
t := table.NewWriter()
27-
t.SetTitle(title)
2826
t.SetOutputMirror(os.Stdout)
29-
t.AppendHeader(header)
27+
t.AppendHeader(row)
3028
return t
3129
}
3230

3331
func renderChartTable(rows []table.Row) {
34-
t := newTable("Charts", table.Row{"#", "Type", "Chart", "Version", "Latest Version", "Latest", "Values", "SubChart", "Version", "Condition", "Enabled"})
32+
t := newTable(table.Row{"#", "Type", "Chart", "Version", "Latest Version", "Latest", "Values", "SubChart", "Version", "Condition", "Enabled"})
3533
t.AppendRows(rows)
3634
t.SortBy([]table.SortBy{
3735
{Number: 1, Mode: table.AscNumeric},
@@ -113,13 +111,13 @@ func RenderChartTable(charts *helm.ChartCollection, setters ...Option) {
113111

114112
func RenderHelmValuePathToImageTable(chartImageHelmValuesMap map[helm.Chart]map[*registry.Image][]string) {
115113
// Print Helm values to be set for each chart
116-
t := newTable("Helm Values Paths Per Image", table.Row{"#", "Helm Chart", "Chart Version", "Image", "Helm Value Path(s)"})
114+
t := newTable(table.Row{"#", "Helm Chart", "Chart Version", "Helm Value Path", "Image"})
117115
id := 0
118116
for c, v := range chartImageHelmValuesMap {
119117
for i, paths := range v {
120118
ref, _ := i.String()
121119
noSHA := strings.SplitN(ref, "@", 2)[0]
122-
t.AppendRow(table.Row{id, c.Name, c.Version, noSHA, strings.Join(paths, "\n")})
120+
t.AppendRow(table.Row{id, c.Name, c.Version, strings.Join(paths, "\n"), noSHA})
123121
id = id + 1
124122
}
125123
}
@@ -152,7 +150,7 @@ func getImportTableRows(ctx context.Context, viper *viper.Viper, registries []re
152150
// Create collection of registry names as keys for iterating registries
153151
keys := make([]string, 0)
154152
for _, r := range registries {
155-
keys = append(keys, r.URL)
153+
keys = append(keys, r.GetName())
156154
}
157155

158156
// Combine results
@@ -165,12 +163,8 @@ func getImportTableRows(ctx context.Context, viper *viper.Viper, registries []re
165163
// make sure we don't parse again
166164
seenImages = append(seenImages, *i)
167165

168-
name, err := i.ImageName()
169-
if err != nil {
170-
return []table.Row{}, err
171-
}
172166
// check if image exists in registry
173-
m := registry.Exists(ctx, name, i.Tag, registries)
167+
m := registry.Exists(ctx, i, registries)
174168

175169
// add row to overview table
176170
ref, _ := i.String()
@@ -184,6 +178,7 @@ func getImportTableRows(ctx context.Context, viper *viper.Viper, registries []re
184178
}
185179

186180
func RenderImageOverviewTable(ctx context.Context, viper *viper.Viper, missing int, registries []registry.Registry, chartImageValuesMap map[helm.Chart]map[*registry.Image][]string) error {
181+
187182
rows, err := getImportTableRows(ctx, viper, registries, chartImageValuesMap)
188183
if err != nil {
189184
return err
@@ -200,86 +195,19 @@ func RenderImageOverviewTable(ctx context.Context, viper *viper.Viper, missing i
200195

201196
// dynamic number of registries
202197
for _, r := range registries {
203-
header = append(header, r.GetName())
204-
footer = append(footer, "")
205-
206-
if ic.Import.Enabled {
207-
// second static part of header
208-
header = append(header, "import")
209-
footer = append(footer, sc.Value(r.URL))
210-
}
211-
}
212-
213-
// construct tab"test"le
214-
t := newTable("Registry Overview For Charts", header)
215-
t.AppendRows(rows)
216-
t.AppendFooter(footer)
217-
t.Render()
218-
219-
return nil
220-
}
221-
222-
func RenderChartOverviewTable(ctx context.Context, viper *viper.Viper, missing int, registries []registry.Registry, charts helm.ChartCollection) error {
223-
224-
// Create collection of registry names as keys for iterating registries
225-
keys := make([]string, 0)
226-
for _, r := range registries {
227-
keys = append(keys, r.URL)
228-
}
229-
230-
// Combine results
231-
rows := make([]table.Row, 0)
232-
for _, c := range charts.Charts {
233-
// check if image exists in registry
234-
m := registry.Exists(ctx, fmt.Sprintf("charts/%s", c.Name), c.Version, registries)
235-
236-
// add row to overview table
237-
row := func() table.Row {
238-
row := table.Row{}
239-
row = append(row, sc.Value("index_import_charts"), c.Name, c.Version)
240-
241-
for _, key := range keys {
242-
row = append(row, terminal.StatusEmoji(m[key]))
243-
ic := state.GetValue[bootstrap.ImportConfigSection](viper, "importConfig")
244-
if ic.Import.Enabled {
245-
b := state.GetValue[bool](viper, "all") || !m[key]
246-
if b {
247-
sc.Inc(key + "charts")
248-
}
249-
row = append(row, terminal.StatusEmoji(b))
250-
}
251-
}
252-
253-
sc.Inc("index_import_charts")
254-
return row
255-
}()
256-
257-
rows = append(rows, row)
258-
}
259-
260-
header := table.Row{}
261-
footer := table.Row{}
262-
263-
// first static part of header
264-
header = append(header, "#", "Helm Chart", "Chart Version")
265-
footer = append(footer, "", "", "")
266-
267-
ic := state.GetValue[bootstrap.ImportConfigSection](viper, "importConfig")
268-
269-
// dynamic number of registries
270-
for _, r := range registries {
271-
header = append(header, r.GetName())
198+
name := r.GetName()
199+
header = append(header, name)
272200
footer = append(footer, "")
273201

274202
if ic.Import.Enabled {
275203
// second static part of header
276204
header = append(header, "import")
277-
footer = append(footer, sc.Value(r.URL+"charts"))
205+
footer = append(footer, sc.Value(r.GetName()))
278206
}
279207
}
280208

281209
// construct table
282-
t := newTable("Registry Overview For Images", header)
210+
t := newTable(header)
283211
t.AppendRows(rows)
284212
t.AppendFooter(footer)
285213
t.Render()

0 commit comments

Comments
 (0)