Output JSON

This commit is contained in:
2026-01-12 22:48:15 +01:00
parent dbbae65e45
commit 66835aab9d
3 changed files with 104 additions and 36 deletions

View File

@@ -4,6 +4,7 @@
package main
import (
"encoding/json"
"flag"
"fmt"
"os"
@@ -90,17 +91,30 @@ func main() {
if *dumpAll {
// Dump all entries in the tile
if err := utils.DumpAllEntries(tileData); err != nil {
result, err := utils.DumpAllEntries(tileData)
if err != nil {
fatal("%v", err)
}
printJSON(result)
} else {
// Dump only the specific entry at the position
if err := utils.DumpEntryAtPosition(tileData, int(positionInTile), leafIndex); err != nil {
entry, err := utils.DumpEntryAtPosition(tileData, int(positionInTile), leafIndex)
if err != nil {
fatal("%v", err)
}
printJSON(entry)
}
}
func printJSON(v interface{}) {
data, err := json.MarshalIndent(v, "", " ")
if err != nil {
fatal("failed to marshal JSON: %v", err)
}
fmt.Println(string(data))
}
func fatal(format string, args ...any) {
fmt.Fprintf(os.Stderr, "Error: "+format+"\n", args...)
os.Exit(1)