mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-01 14:14:52 +08:00
Use file extension to auto detect output format!
This commit is contained in:
@@ -43,17 +43,18 @@ func InputFormatFromString(format string) (InputFormat, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func InputFormatFromFilename(filename string, defaultFormat string) string {
|
||||
func FormatFromFilename(filename string) string {
|
||||
|
||||
if filename != "" {
|
||||
GetLogger().Debugf("checking filename '%s' for inputFormat", filename)
|
||||
GetLogger().Debugf("checking file extension '%s' for auto format detection", filename)
|
||||
nPos := strings.LastIndex(filename, ".")
|
||||
if nPos > -1 {
|
||||
inputFormat := filename[nPos+1:]
|
||||
GetLogger().Debugf("detected inputFormat '%s'", inputFormat)
|
||||
return inputFormat
|
||||
format := filename[nPos+1:]
|
||||
GetLogger().Debugf("detected format '%s'", format)
|
||||
return format
|
||||
}
|
||||
}
|
||||
|
||||
GetLogger().Debugf("using default inputFormat '%s'", defaultFormat)
|
||||
return defaultFormat
|
||||
GetLogger().Debugf("using default inputFormat 'yaml'")
|
||||
return "yaml"
|
||||
}
|
||||
|
||||
@@ -33,11 +33,11 @@ const (
|
||||
|
||||
func OutputFormatFromString(format string) (PrinterOutputFormat, error) {
|
||||
switch format {
|
||||
case "yaml", "y":
|
||||
case "yaml", "y", "yml":
|
||||
return YamlOutputFormat, nil
|
||||
case "json", "j":
|
||||
return JSONOutputFormat, nil
|
||||
case "props", "p":
|
||||
case "props", "p", "properties":
|
||||
return PropsOutputFormat, nil
|
||||
case "csv", "c":
|
||||
return CSVOutputFormat, nil
|
||||
|
||||
Reference in New Issue
Block a user