Add conversion functionality from yml to toml

This commit is contained in:
2025-10-26 15:05:02 +01:00
parent 9d9820072a
commit 302e874710
3 changed files with 137 additions and 2 deletions

26
main.go
View File

@@ -46,11 +46,16 @@ func main() {
fmt.Fprintf(os.Stderr, " Set logging level: ERROR, WARNING, INFO, DEBUG, TRACE (default \"INFO\")\n")
fmt.Fprintf(os.Stderr, " -json\n")
fmt.Fprintf(os.Stderr, " Enable JSON mode for processing JSON files\n")
fmt.Fprintf(os.Stderr, " -conv\n")
fmt.Fprintf(os.Stderr, " Convert YAML files to TOML format\n")
fmt.Fprintf(os.Stderr, "\nExamples:\n")
fmt.Fprintf(os.Stderr, " Regex mode (default):\n")
fmt.Fprintf(os.Stderr, " %s \"<value>(\\\\d+)</value>\" \"*1.5\" data.xml\n", os.Args[0])
fmt.Fprintf(os.Stderr, " JSON mode:\n")
fmt.Fprintf(os.Stderr, " %s -json data.json\n", os.Args[0])
fmt.Fprintf(os.Stderr, " YAML to TOML conversion:\n")
fmt.Fprintf(os.Stderr, " %s -conv *.yml\n", os.Args[0])
fmt.Fprintf(os.Stderr, " %s -conv **/*.yaml\n", os.Args[0])
fmt.Fprintf(os.Stderr, "\nNote: v1, v2, etc. are used to refer to capture groups as numbers.\n")
fmt.Fprintf(os.Stderr, " s1, s2, etc. are used to refer to capture groups as strings.\n")
fmt.Fprintf(os.Stderr, " Helper functions: num(str) converts string to number, str(num) converts number to string\n")
@@ -74,6 +79,27 @@ func main() {
return
}
// Handle YAML to TOML conversion if -conv flag is set
if *utils.Convert {
mainLogger.Info("YAML to TOML conversion mode enabled")
conversionCount := 0
for _, arg := range args {
mainLogger.Debug("Converting YAML files matching pattern: %s", arg)
err := utils.ConvertYAMLToTOML(arg)
if err != nil {
mainLogger.Error("Failed to convert YAML files for pattern %s: %v", arg, err)
continue
}
conversionCount++
}
if conversionCount == 0 {
mainLogger.Warning("No files were converted. Please check your patterns.")
} else {
mainLogger.Info("Conversion completed for %d pattern(s)", conversionCount)
}
return
}
mainLogger.Debug("Getting database connection")
db, err := utils.GetDB()
if err != nil {