Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
Pretty print schema if JSON object; close #3
Browse files Browse the repository at this point in the history
  • Loading branch information
rollulus committed Jun 30, 2016
1 parent 7424901 commit dddd74d
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions schema-registry-cli/cmd/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package cmd

import (
"bufio"
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"log"
Expand All @@ -19,6 +21,18 @@ func stdinToString() string {
return string(bs)
}

func printSchema(sch schemaregistry.Schema) {
log.Printf("version: %d\n", sch.Version)
log.Printf("id: %d\n", sch.Id)
var indented bytes.Buffer
if err := json.Indent(&indented, []byte(sch.Schema), "", " "); err != nil {
fmt.Println(sch.Schema) //isn't a json object, which is legal
return
}
indented.WriteTo(os.Stdout)
os.Stdout.WriteString("\n")
}

func getById(id int) error {
cl := assertClient()
sch, err := cl.GetSchemaById(id)
Expand All @@ -35,9 +49,7 @@ func getLatestBySubject(subj string) error {
if err != nil {
return err
}
log.Printf("version: %d\n", sch.Version)
log.Printf("id: %d\n", sch.Id)
fmt.Println(sch.Schema)
printSchema(sch)
return nil
}

Expand All @@ -47,9 +59,7 @@ func getBySubjectVersion(subj string, ver int) error {
if err != nil {
return err
}
log.Printf("version: %d\n", sch.Version)
log.Printf("id: %d\n", sch.Id)
fmt.Println(sch.Schema)
printSchema(sch)
return nil
}

Expand Down

0 comments on commit dddd74d

Please sign in to comment.