Output JSON
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user