mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
23d3d962e0
- improved comment handling - yaml decoder now responsible for leading content work around
43 lines
810 B
Go
43 lines
810 B
Go
package yqlib
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
)
|
|
|
|
type InputFormat uint
|
|
|
|
const (
|
|
YamlInputFormat = 1 << iota
|
|
XMLInputFormat
|
|
PropertiesInputFormat
|
|
Base64InputFormat
|
|
JsonInputFormat
|
|
CSVObjectInputFormat
|
|
TSVObjectInputFormat
|
|
)
|
|
|
|
type Decoder interface {
|
|
Init(reader io.Reader) error
|
|
Decode() (*CandidateNode, 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
|
|
case "json", "ndjson", "j":
|
|
return JsonInputFormat, nil
|
|
case "csv", "c":
|
|
return CSVObjectInputFormat, nil
|
|
case "tsv", "t":
|
|
return TSVObjectInputFormat, nil
|
|
default:
|
|
return 0, fmt.Errorf("unknown format '%v' please use [yaml|xml|props]", format)
|
|
}
|
|
}
|