MCPcopy Create free account
hub / github.com/cloudbase/garm / formatGARMToolsList

Function formatGARMToolsList

cmd/garm-cli/cmd/controller.go:569–617  ·  view source on GitHub ↗
(files params.GARMAgentToolsPaginatedResponse, upstream bool)

Source from the content-addressed store, hash-verified

567}
568
569func formatGARMToolsList(files params.GARMAgentToolsPaginatedResponse, upstream bool) {
570 if outputFormat == common.OutputFormatJSON {
571 printAsJSON(files)
572 return
573 }
574 t := table.NewWriter()
575 t.Style().Options.SeparateHeader = true
576 t.Style().Options.SeparateRows = true
577
578 var numCols int
579 var header table.Row
580 if upstream {
581 numCols = 6
582 header = table.Row{"Name", "Size", "Version", "OS Type", "OS Architecture", "Download URL"}
583 } else {
584 numCols = 8
585 header = table.Row{"ID", "Name", "Size", "Version", "OS Type", "OS Architecture", "Created", "Updated"}
586 }
587
588 // Page header - fill all columns with the same text
589 pageHeaderText := fmt.Sprintf("Page %d of %d", files.CurrentPage, files.Pages)
590 pageHeader := make(table.Row, numCols)
591 for i := range pageHeader {
592 pageHeader[i] = pageHeaderText
593 }
594 t.AppendHeader(pageHeader, table.RowConfig{
595 AutoMerge: true,
596 AutoMergeAlign: text.AlignCenter,
597 })
598 t.AppendHeader(header)
599
600 if upstream {
601 t.SetColumnConfigs([]table.ColumnConfig{
602 {Number: 2, Align: text.AlignRight},
603 })
604 for _, val := range files.Results {
605 t.AppendRow(table.Row{val.Name, formatSize(val.Size), val.Version, val.OSType, val.OSArch, val.DownloadURL})
606 }
607 } else {
608 t.SetColumnConfigs([]table.ColumnConfig{
609 {Number: 1, Align: text.AlignRight},
610 {Number: 3, Align: text.AlignRight},
611 })
612 for _, val := range files.Results {
613 t.AppendRow(table.Row{val.ID, val.Name, formatSize(val.Size), val.Version, val.OSType, val.OSArch, val.CreatedAt, val.UpdatedAt})
614 }
615 }
616 fmt.Println(t.Render())
617}

Callers 1

controller.goFile · 0.85

Calls 2

printAsJSONFunction · 0.85
formatSizeFunction · 0.85

Tested by

no test coverage detected