(files params.FileObjectPaginatedResponse)
| 535 | } |
| 536 | |
| 537 | func formatFileObjsList(files params.FileObjectPaginatedResponse) { |
| 538 | if outputFormat == common.OutputFormatJSON { |
| 539 | printAsJSON(files) |
| 540 | return |
| 541 | } |
| 542 | t := table.NewWriter() |
| 543 | // Define column count |
| 544 | numCols := 6 |
| 545 | t.Style().Options.SeparateHeader = true |
| 546 | t.Style().Options.SeparateRows = true |
| 547 | |
| 548 | // Page header - fill all columns with the same text |
| 549 | pageHeaderText := fmt.Sprintf("Page %d of %d", files.CurrentPage, files.Pages) |
| 550 | pageHeader := make(table.Row, numCols) |
| 551 | for i := range pageHeader { |
| 552 | pageHeader[i] = pageHeaderText |
| 553 | } |
| 554 | t.AppendHeader(pageHeader, table.RowConfig{ |
| 555 | AutoMerge: true, |
| 556 | AutoMergeAlign: text.AlignCenter, |
| 557 | }) |
| 558 | // Column headers |
| 559 | header := table.Row{"ID", "Name", "Size", "Tags", "Created", "Updated"} |
| 560 | t.AppendHeader(header) |
| 561 | // Right-align numeric columns |
| 562 | t.SetColumnConfigs([]table.ColumnConfig{ |
| 563 | {Number: 1, Align: text.AlignRight}, |
| 564 | {Number: 3, Align: text.AlignRight}, |
| 565 | }) |
| 566 | |
| 567 | for _, val := range files.Results { |
| 568 | row := table.Row{val.ID, val.Name, formatSize(val.Size), strings.Join(val.Tags, ", "), val.CreatedAt.Format("2006-01-02 15:04:05"), val.UpdatedAt.Format("2006-01-02 15:04:05")} |
| 569 | t.AppendRow(row) |
| 570 | } |
| 571 | fmt.Println(t.Render()) |
| 572 | } |
| 573 | |
| 574 | func formatSize(bytes int64) string { |
| 575 | const unit = 1024 |
no test coverage detected