41 lines
899 B
Go
41 lines
899 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"git.kotmisia.pl/Mm2PL/examples"
|
|
)
|
|
|
|
func main() {
|
|
files := flag.String("files", "", "Comma separated list of files to convert to JSON.")
|
|
flag.Parse()
|
|
if *files == "" {
|
|
fmt.Fprintf(os.Stderr, "The -files flag is required.")
|
|
return
|
|
}
|
|
var allExamples []examples.Example
|
|
for _, file := range strings.Split(*files, ",") {
|
|
file = strings.Trim(file, " ")
|
|
f, err := os.Open(file)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Failed to open %s for reading: %s\n", file, err)
|
|
continue
|
|
}
|
|
exs, err := examples.ReadFile(f)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Failed to parse %s: %s\n", file, err)
|
|
continue
|
|
}
|
|
allExamples = append(allExamples, exs...)
|
|
}
|
|
err := json.NewEncoder(os.Stdout).Encode(&allExamples)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Failed to encode JSON: %s\n", err)
|
|
return
|
|
}
|
|
}
|