Skip to content

Commit

Permalink
Merge pull request #3 from go-playground/correct-json-output
Browse files Browse the repository at this point in the history
Correct json output
  • Loading branch information
Dean Karn authored Jun 9, 2022
2 parents 77bf1a9 + 0c49652 commit 1f6e2e6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.1.0] - 2022-06-08
### Fixed
- CLI output to be JSON.

## [0.1.0] - 2022-03-23
### Added
- Initial conversion from https://github.com/rust-playground/ksql.

[Unreleased]: https://github.com/go-playground/ksql/compare/v0.1.0...HEAD
[0.1.0]: https://github.com/rust-playground/ksql/commit/v0.1.0
[Unreleased]: https://github.com/go-playground/ksql/compare/v0.1.1...HEAD
[0.1.1]: https://github.com/go-playground/ksql/compare/v0.1.0...v0.1.1
[0.1.0]: https://github.com/go-playground/ksql/commit/v0.1.0
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ksql
=====
![Project status](https://img.shields.io/badge/version-0.1.0-green.svg)
![Project status](https://img.shields.io/badge/version-0.1.1-green.svg)
[![GoDoc](https://godoc.org/github.com/go-playground/ksql?status.svg)](https://pkg.go.dev/github.com/go-playground/ksql)
![License](https://img.shields.io/dub/l/vibe-d.svg)

Expand Down
27 changes: 25 additions & 2 deletions cmd/ksql/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

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

Expand Down Expand Up @@ -35,10 +36,20 @@ func main() {
fmt.Fprintln(os.Stderr, "reading standard input:", err)
return
}
if _, err = fmt.Fprintln(w, result); err != nil {
b, err := json.Marshal(result)
if err != nil {
fmt.Fprintln(os.Stderr, "converting results to JSON:", err)
return
}
if _, err = w.Write(b); err != nil {
fmt.Fprintln(os.Stderr, "writing standard output:", err)
return
}
if _, err = os.Stdout.Write([]byte{'\n'}); err != nil {
fmt.Fprintln(os.Stderr, "writing standard output:", err)
return
}

}
if err := scanner.Err(); err != nil {
fmt.Fprintln(os.Stderr, "reading standard input:", err)
Expand All @@ -53,7 +64,19 @@ func main() {
usage()
return
}
fmt.Println(result)
b, err := json.Marshal(result)
if err != nil {
fmt.Fprintln(os.Stderr, "converting results to JSON:", err)
return
}
if _, err = os.Stdout.Write(b); err != nil {
fmt.Fprintln(os.Stderr, "writing standard output:", err)
return
}
if _, err = os.Stdout.Write([]byte{'\n'}); err != nil {
fmt.Fprintln(os.Stderr, "writing standard output:", err)
return
}
}
}

Expand Down

0 comments on commit 1f6e2e6

Please sign in to comment.