Use file extension to auto detect output format!

This commit is contained in:
Mike Farah
2023-03-15 13:14:40 +11:00
parent 2c14c98408
commit c1a236d720
10 changed files with 107 additions and 110 deletions
+8 -7
View File
@@ -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"
}
+2 -2
View File
@@ -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