Skip to content

Commit

Permalink
format as json
Browse files Browse the repository at this point in the history
id -> name
  • Loading branch information
tmck-code committed Apr 4, 2024
1 parent 358fec0 commit 50a808c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pokesay.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package main

import (
"embed"
"encoding/json"
"fmt"
"os"
"strings"

"github.com/pborman/getopt/v2"
Expand Down Expand Up @@ -110,12 +112,12 @@ func runListNames() {
names := pokesay.ListNames(
pokedex.ReadStructFromBytes[map[string][]int](GOBAllNames),
)
s := make([]string, 0)
s := make(map[string]string)
for i, name := range names {
s = append(s, fmt.Sprintf("%d:%s", i, name))
s[fmt.Sprintf("%03d", i)] = name
}
fmt.Println(strings.Join(s, ", "))
// fmt.Printf("%s\n%d %s\n", strings.Join(names, " "), len(names), "total names")
json, _ := json.MarshalIndent(s, "", strings.Repeat(" ", 2))
fmt.Fprintln(os.Stderr, string(json))
}

// GenerateNames returns a list of names to print
Expand Down

0 comments on commit 50a808c

Please sign in to comment.