@@ -2,7 +2,6 @@ package output
22
33import (
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
2221var 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
3331func 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
114112func 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
186180func 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