sq/cli/output/format/format.go
Neil O'Toole 2f2dfd6e47
#229: More diff (#233)
- Implement `sq diff --data`.
2023-05-22 09:08:14 -06:00

66 lines
1.2 KiB
Go

package format
import (
"github.com/neilotoole/sq/libsq/core/errz"
)
// Format is an output format such as json or xml.
type Format string
// UnmarshalText implements encoding.TextUnmarshaler.
func (f *Format) UnmarshalText(text []byte) error {
switch Format(text) {
default:
return errz.Errorf("unknown output format {%s}", string(text))
case JSON, JSONA, JSONL, Text, Raw,
HTML, Markdown, XLSX, XML,
CSV, TSV, YAML:
case "table":
// Legacy: the "text" format used to be named "table".
// text = []byte(Text)
// FIXME: Probably should return an error now?
}
*f = Format(text)
return nil
}
// String returns the format value.
func (f Format) String() string {
return string(f)
}
// Output format values.
const (
Text Format = "text"
JSON Format = "json"
JSONL Format = "jsonl"
JSONA Format = "jsona"
HTML Format = "html"
Markdown Format = "markdown"
XLSX Format = "xlsx"
XML Format = "xml"
CSV Format = "csv"
TSV Format = "tsv"
Raw Format = "raw"
YAML Format = "yaml"
)
// All returns a new slice containing all format.Format values.
func All() []Format {
return []Format{
Text,
JSON,
JSONL,
JSONA,
Raw,
HTML,
Markdown,
XLSX,
XML,
CSV,
TSV,
YAML,
}
}