(v interface{})
| 78 | } |
| 79 | |
| 80 | func (p *Printer) PrintData(v interface{}) { |
| 81 | out := p.dataOut() |
| 82 | switch p.Format { |
| 83 | case FormatHuman: |
| 84 | var b strings.Builder |
| 85 | tableprinter.Default.RowCharLimit = 120 |
| 86 | tableprinter.Print(&b, v) |
| 87 | fmt.Fprint(out, b.String()) |
| 88 | case FormatJSON: |
| 89 | buf, err := json.MarshalIndent(v, "", " ") |
| 90 | if err != nil { |
| 91 | panic(fmt.Errorf("failed to marshal JSON: %w", err)) |
| 92 | } |
| 93 | fmt.Fprintln(out, string(buf)) |
| 94 | case FormatCSV: |
| 95 | buf, err := gocsv.MarshalString(v) |
| 96 | if err != nil { |
| 97 | panic(fmt.Errorf("failed to marshal CSV: %w", err)) |
| 98 | } |
| 99 | fmt.Fprint(out, buf) |
| 100 | default: |
| 101 | panic(fmt.Errorf("unexpected print format <%v>", p.Format)) |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | func (p *Printer) PrintDataWithTitle(v interface{}, title string) { |
| 106 | if p.Format == FormatHuman { |
no test coverage detected