summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/mattermost/rsc/cmd/jfmt/main.go
blob: 31c5eddfc2f4a751e4d6a72ab1784cd225c4f3be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright 2012 The Go Authors.  All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// jfmt reads JSON from standard input, formats it, and writes it to standard output.
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"log"
	"os"
)

func main() {
	log.SetFlags(0)

	if len(os.Args) > 1 {
		fmt.Fprintf(os.Stderr, "usage: json < input > output\n")
		os.Exit(2)
	}
	
	// TODO: Can do on the fly.
	
	data, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		log.Fatal(err)
	}
	
	var buf bytes.Buffer
	json.Indent(&buf, data, "", "    ")
	buf.WriteByte('\n')

	os.Stdout.Write(buf.Bytes())
}