43 lines
879 B
Go
43 lines
879 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"flag"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"os"
|
|
|
|
"git.lattuga.net/blallo/gotools/formatting"
|
|
)
|
|
|
|
func showExamples() {
|
|
enc := json.NewEncoder(os.Stderr)
|
|
for i, example := range examples {
|
|
fmt.Fprintf(os.Stderr, "\nExample %d\n\nInput:\n\n", i)
|
|
formatting.PrettyPrint(example)
|
|
fmt.Fprintf(os.Stderr, "\nOutput:\n\n")
|
|
formatting.EncodeJSON(example, enc)
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
filepath := flag.String("file", "", "Path to a file of paths with descriptions")
|
|
flag.Parse()
|
|
var input map[string]string
|
|
if *filepath != "" {
|
|
filecont, err := ioutil.ReadFile(*filepath)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
err = json.Unmarshal(filecont, &input)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
} else {
|
|
fmt.Fprintf(os.Stderr, "Missing input file!\n")
|
|
showExamples()
|
|
os.Exit(1)
|
|
}
|
|
enc := json.NewEncoder(os.Stdout)
|
|
formatting.EncodeJSON(input, enc)
|
|
}
|