Skip to content

Commit

Permalink
atg. pretty json output on -write-schema
Browse files Browse the repository at this point in the history
  • Loading branch information
glycerine committed Dec 25, 2016
1 parent 5826372 commit eab0152
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ package main

import (
"bytes"
"encoding/json"
"flag"
"fmt"
"io"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -165,8 +167,20 @@ func saveMsgpackFile(parsedPath, path string, fs *parse.FileSet) error {
}
defer fjson.Close()

// and write out pretty json version too.
buf := bytes.NewBuffer(by)
_, err = msgp.CopyToJSON(fjson, buf)
var compactJson, pretty bytes.Buffer
_, err = msgp.CopyToJSON(&compactJson, buf)
if err != nil {
return err
}

err = json.Indent(&pretty, compactJson.Bytes(), "", " ")
if err != nil {
return err
}
_, err = io.Copy(fjson, &pretty)
fmt.Fprintf(fjson, "\n")
return err
}
return nil
Expand Down

0 comments on commit eab0152

Please sign in to comment.