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

Commit

Permalink
pretty print jsons
Browse files Browse the repository at this point in the history
  • Loading branch information
henrod committed Jun 26, 2019
1 parent afed6e1 commit 50f16b5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ go get -u github.com/topfreegames/pitaya-cli
```

## Usage

For cli flags, run `pitaya-cli --help`

```
$ pitaya-cli
Expand Down
13 changes: 12 additions & 1 deletion helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package main

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

Expand Down Expand Up @@ -69,7 +70,7 @@ func readServerMessages(callback func(data []byte)) {
close(disconnectedCh)
return
case m := <-channel:
callback(m.Data)
callback(parseData(m.Data))
}
}
}
Expand All @@ -83,3 +84,13 @@ func configure(c *ishell.Shell) {

c.SetHistoryPath(historyPath)
}

func parseData(data []byte) []byte {
if prettyJSON {
var m interface{}
_ = json.Unmarshal(data, &m)
data, _ = json.MarshalIndent(m, "", "\t")
}

return data
}
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ var (
fileName string
pushInfo map[string]string
wait sync.WaitGroup
prettyJSON bool
)

func main() {
flag.StringVar(&docsString, "docs", "", "documentation route")
flag.StringVar(&fileName, "filename", "", "file with commands")
flag.BoolVar(&prettyJSON, "pretty", false, "print pretty jsons")
flag.Parse()

switch {
Expand Down

0 comments on commit 50f16b5

Please sign in to comment.