@@ -300,120 +300,96 @@ func outputResult(p *print.Printer, model *inputModel, flavors *sqlserverflex.Li
300300}
301301
302302func outputResultAsTable (p * print.Printer , model * inputModel , options * options ) error {
303- content := ""
304- if model .Flavors {
305- content += renderFlavors ( * options .Flavors )
303+ content := []tables. Table {}
304+ if model .Flavors && len ( * options . Flavors ) != 0 {
305+ content = append ( content , buildFlavorsTable ( * options .Flavors ) )
306306 }
307- if model .Versions {
308- content += renderVersions ( * options .Versions )
307+ if model .Versions && len ( * options . Versions ) != 0 {
308+ content = append ( content , buildVersionsTable ( * options .Versions ) )
309309 }
310- if model .Storages {
311- content += renderStorages ( options .Storages .Storages )
310+ if model .Storages && options . Storages . Storages != nil && len ( * options . Storages . Storages . StorageClasses ) != 0 {
311+ content = append ( content , buildStoragesTable ( * options .Storages .Storages ) )
312312 }
313- if model .UserRoles {
314- content += renderUserRoles ( options .UserRoles )
313+ if model .UserRoles && len ( options . UserRoles . UserRoles ) != 0 {
314+ content = append ( content , buildUserRoles ( options .UserRoles ) )
315315 }
316- if model .DBCompatibilities {
317- content += renderDBCompatibilities ( options .DBCompatibilities )
316+ if model .DBCompatibilities && len ( options . DBCompatibilities . DBCompatibilities ) != 0 {
317+ content = append ( content , buildDBCompatibilitiesTable ( options .DBCompatibilities . DBCompatibilities ) )
318318 }
319319 // Rendered at last because table is very long
320- if model .DBCollations {
321- content += renderDBCollations ( options .DBCollations )
320+ if model .DBCollations && len ( options . DBCollations . DBCollations ) != 0 {
321+ content = append ( content , buildDBCollationsTable ( options .DBCollations . DBCollations ) )
322322 }
323323
324- err := p . PagerDisplay ( content )
324+ err := tables . DisplayTables ( p , content )
325325 if err != nil {
326326 return fmt .Errorf ("display output: %w" , err )
327327 }
328328
329329 return nil
330330}
331331
332- func renderFlavors (flavors []sqlserverflex.InstanceFlavorEntry ) string {
333- if len (flavors ) == 0 {
334- return ""
335- }
336-
332+ func buildFlavorsTable (flavors []sqlserverflex.InstanceFlavorEntry ) tables.Table {
337333 table := tables .NewTable ()
338334 table .SetTitle ("Flavors" )
339335 table .SetHeader ("ID" , "CPU" , "MEMORY" , "DESCRIPTION" , "VALID INSTANCE TYPES" )
340336 for i := range flavors {
341337 f := flavors [i ]
342338 table .AddRow (* f .Id , * f .Cpu , * f .Memory , * f .Description , * f .Categories )
343339 }
344- return table . Render ()
340+ return table
345341}
346342
347- func renderVersions (versions []string ) string {
348- if len (versions ) == 0 {
349- return ""
350- }
351-
343+ func buildVersionsTable (versions []string ) tables.Table {
352344 table := tables .NewTable ()
353345 table .SetTitle ("Versions" )
354346 table .SetHeader ("VERSION" )
355347 for i := range versions {
356348 v := versions [i ]
357349 table .AddRow (v )
358350 }
359- return table . Render ()
351+ return table
360352}
361353
362- func renderStorages (resp * sqlserverflex.ListStoragesResponse ) string {
363- if resp .StorageClasses == nil || len (* resp .StorageClasses ) == 0 {
364- return ""
365- }
366- storageClasses := * resp .StorageClasses
367-
354+ func buildStoragesTable (storagesResp sqlserverflex.ListStoragesResponse ) tables.Table {
355+ storages := * storagesResp .StorageClasses
368356 table := tables .NewTable ()
369357 table .SetTitle ("Storages" )
370358 table .SetHeader ("MINIMUM" , "MAXIMUM" , "STORAGE CLASS" )
371- for i := range storageClasses {
372- sc := storageClasses [i ]
373- table .AddRow (* resp .StorageRange .Min , * resp .StorageRange .Max , sc )
359+ for i := range storages {
360+ sc := storages [i ]
361+ table .AddRow (* storagesResp .StorageRange .Min , * storagesResp .StorageRange .Max , sc )
374362 }
375363 table .EnableAutoMergeOnColumns (1 , 2 , 3 )
376- return table . Render ()
364+ return table
377365}
378366
379- func renderUserRoles (roles * instanceUserRoles ) string {
380- if len (roles .UserRoles ) == 0 {
381- return ""
382- }
383-
367+ func buildUserRoles (roles * instanceUserRoles ) tables.Table {
384368 table := tables .NewTable ()
385369 table .SetTitle ("User Roles" )
386370 table .SetHeader ("ROLE" )
387371 for i := range roles .UserRoles {
388372 table .AddRow (roles .UserRoles [i ])
389373 }
390- return table . Render ()
374+ return table
391375}
392376
393- func renderDBCollations (dbCollations * instanceDBCollations ) string {
394- if len (dbCollations .DBCollations ) == 0 {
395- return ""
396- }
397-
377+ func buildDBCollationsTable (dbCollations []sqlserverflex.MssqlDatabaseCollation ) tables.Table {
398378 table := tables .NewTable ()
399379 table .SetTitle ("DB Collations" )
400380 table .SetHeader ("NAME" , "DESCRIPTION" )
401- for i := range dbCollations . DBCollations {
402- table .AddRow (* dbCollations . DBCollations [i ].CollationName , * dbCollations . DBCollations [i ].Description )
381+ for i := range dbCollations {
382+ table .AddRow (dbCollations [i ].CollationName , dbCollations [i ].Description )
403383 }
404- return table . Render ()
384+ return table
405385}
406386
407- func renderDBCompatibilities (dbCompatibilities * instanceDBCompatibilities ) string {
408- if len (dbCompatibilities .DBCompatibilities ) == 0 {
409- return ""
410- }
411-
387+ func buildDBCompatibilitiesTable (dbCompatibilities []sqlserverflex.MssqlDatabaseCompatibility ) tables.Table {
412388 table := tables .NewTable ()
413389 table .SetTitle ("DB Compatibilities" )
414390 table .SetHeader ("COMPATIBILITY LEVEL" , "DESCRIPTION" )
415- for i := range dbCompatibilities . DBCompatibilities {
416- table .AddRow (* dbCompatibilities . DBCompatibilities [i ].CompatibilityLevel , * dbCompatibilities . DBCompatibilities [i ].Description )
391+ for i := range dbCompatibilities {
392+ table .AddRow (dbCompatibilities [i ].CompatibilityLevel , dbCompatibilities [i ].Description )
417393 }
418- return table . Render ()
394+ return table
419395}
0 commit comments