Create map to hold both cases and populate

This commit is contained in:
BenTrapani 2016-07-29 15:29:21 -04:00
parent 2c325e3c76
commit 67c61e436f

View File

@ -75,7 +75,7 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/campoy/jsonenums/parser" "github.com/BenjaminTrapani/jsonenums/parser"
) )
var ( var (
@ -84,6 +84,11 @@ var (
outputSuffix = flag.String("suffix", "_jsonenums", "suffix to be added to the output file") outputSuffix = flag.String("suffix", "_jsonenums", "suffix to be added to the output file")
) )
type CammelSnakePair struct {
CammelRep string
SnakeRep string
}
func main() { func main() {
flag.Parse() flag.Parse()
if len(*typeNames) == 0 { if len(*typeNames) == 0 {
@ -112,11 +117,11 @@ func main() {
var analysis = struct { var analysis = struct {
Command string Command string
PackageName string PackageName string
TypesAndValues map[string][]string TypesAndValues map[string][]CammelSnakePair
}{ }{
Command: strings.Join(os.Args[1:], " "), Command: strings.Join(os.Args[1:], " "),
PackageName: pkg.Name, PackageName: pkg.Name,
TypesAndValues: make(map[string][]string), TypesAndValues: make(map[string][]CammelSnakePair),
} }
// Run generate for each type. // Run generate for each type.
@ -125,7 +130,14 @@ func main() {
if err != nil { if err != nil {
log.Fatalf("finding values for type %v: %v", typeName, err) log.Fatalf("finding values for type %v: %v", typeName, err)
} }
analysis.TypesAndValues[typeName] = values
cammelSnakePairs := make([]CammelSnakePair, len(values))
for i, value := range values {
cammelSnakePairs[i].CammelRep = value
cammelSnakePairs[i].SnakeRep = ToSnake(value)
}
analysis.TypesAndValues[typeName] = cammelSnakePairs
var buf bytes.Buffer var buf bytes.Buffer
if err := generatedTmpl.Execute(&buf, analysis); err != nil { if err := generatedTmpl.Execute(&buf, analysis); err != nil {