2022-04-17 12:30:33 +02:00
|
|
|
package report
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/pkg/clean"
|
|
|
|
)
|
|
|
|
|
2022-10-10 16:34:07 +02:00
|
|
|
// RenderFormat returns a text-formatted table, optionally as valid Markdown,
|
2022-04-17 12:30:33 +02:00
|
|
|
// so the output can be pasted into the docs.
|
2022-10-10 16:34:07 +02:00
|
|
|
func RenderFormat(rows [][]string, cols []string, format Format) (string, error) {
|
2022-04-17 12:30:33 +02:00
|
|
|
switch format {
|
2022-10-10 16:34:07 +02:00
|
|
|
case CSV:
|
|
|
|
return Render(rows, cols, Options{Format: CSV})
|
|
|
|
case TSV:
|
|
|
|
return Render(rows, cols, Options{Format: TSV})
|
|
|
|
case Markdown:
|
|
|
|
return Render(rows, cols, Options{Format: Markdown, Valid: true})
|
|
|
|
case Default:
|
|
|
|
return Render(rows, cols, Options{Format: Default, Valid: false})
|
|
|
|
default:
|
|
|
|
return "", fmt.Errorf("invalid format %s", clean.Log(string(format)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Render returns a text-formatted table, optionally as valid Markdown,
|
|
|
|
// so the output can be pasted into the docs.
|
|
|
|
func Render(rows [][]string, cols []string, opt Options) (string, error) {
|
|
|
|
switch opt.Format {
|
2022-04-17 12:30:33 +02:00
|
|
|
case CSV:
|
|
|
|
return CsvExport(rows, cols, ';')
|
|
|
|
case TSV:
|
|
|
|
return CsvExport(rows, cols, '\t')
|
|
|
|
case Markdown:
|
2022-10-10 16:34:07 +02:00
|
|
|
opt.Valid = true
|
|
|
|
return MarkdownTable(rows, cols, opt), nil
|
2022-04-17 12:30:33 +02:00
|
|
|
case Default:
|
2022-10-10 16:34:07 +02:00
|
|
|
opt.Valid = false
|
|
|
|
return MarkdownTable(rows, cols, opt), nil
|
2022-04-17 12:30:33 +02:00
|
|
|
default:
|
2022-10-10 16:34:07 +02:00
|
|
|
return "", fmt.Errorf("invalid format %s", clean.Log(string(opt.Format)))
|
2022-04-17 12:30:33 +02:00
|
|
|
}
|
|
|
|
}
|