2022-02-10 01:02:53 +00:00
|
|
|
package yqlib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
|
|
|
|
yaml "gopkg.in/yaml.v3"
|
|
|
|
)
|
|
|
|
|
|
|
|
type InputFormat uint
|
|
|
|
|
|
|
|
const (
|
|
|
|
YamlInputFormat = 1 << iota
|
|
|
|
XMLInputFormat
|
|
|
|
PropertiesInputFormat
|
2022-02-22 22:26:35 +00:00
|
|
|
Base64InputFormat
|
2022-07-27 02:26:22 +00:00
|
|
|
JsonInputFormat
|
2022-08-01 00:28:34 +00:00
|
|
|
CSVObjectInputFormat
|
|
|
|
TSVObjectInputFormat
|
2022-02-10 01:02:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Decoder interface {
|
|
|
|
Init(reader io.Reader)
|
|
|
|
Decode(node *yaml.Node) error
|
|
|
|
}
|
|
|
|
|
|
|
|
func InputFormatFromString(format string) (InputFormat, error) {
|
|
|
|
switch format {
|
|
|
|
case "yaml", "y":
|
|
|
|
return YamlInputFormat, nil
|
|
|
|
case "xml", "x":
|
|
|
|
return XMLInputFormat, nil
|
|
|
|
case "props", "p":
|
|
|
|
return PropertiesInputFormat, nil
|
2022-07-27 02:26:22 +00:00
|
|
|
case "json", "ndjson", "j":
|
|
|
|
return JsonInputFormat, nil
|
2022-08-01 00:28:34 +00:00
|
|
|
case "csv", "c":
|
|
|
|
return CSVObjectInputFormat, nil
|
|
|
|
case "tsv", "t":
|
|
|
|
return TSVObjectInputFormat, nil
|
2022-02-10 01:02:53 +00:00
|
|
|
default:
|
|
|
|
return 0, fmt.Errorf("unknown format '%v' please use [yaml|xml|props]", format)
|
|
|
|
}
|
|
|
|
}
|