-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.go
54 lines (46 loc) · 1.23 KB
/
main.go
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//go:generate go run --tags=generate assets_generate.go
package main
import (
"encoding/json"
"io/ioutil"
"log"
"os"
"path"
"github.com/exercism/go-analyzer/analyzer"
"github.com/namsral/flag"
)
var (
exercise = flag.String("exercise", "", "exercise slug (e.g. 'two-fer')")
solutionPath = flag.String("solution", "", "path to solution to be processed")
output = flag.String("output", "analysis.json", "name of the output file")
)
func main() {
flag.Parse()
if *exercise == "" || *solutionPath == "" {
if flag.NArg() < 2 {
flag.Usage()
os.Exit(1)
}
args := flag.Args()
*exercise, *solutionPath = args[0], args[1]
}
log.Printf("Starting check for `%s` exercise in folder `%s`\n", *exercise, *solutionPath)
res := analyzer.Analyze(*exercise, *solutionPath)
for _, errStr := range res.Errors {
log.Println(errStr)
}
bytes, err := toJSON(res)
if err != nil {
log.Printf("%+v", err)
os.Exit(2)
}
outputFile := path.Join(*solutionPath, *output)
if err := ioutil.WriteFile(outputFile, append(bytes, '\n'), 0644); err != nil {
log.Printf("%+v", err)
os.Exit(3)
}
log.Printf("Output written to %s", outputFile)
}
func toJSON(res interface{}) ([]byte, error) {
return json.MarshalIndent(res, "", "\t")
}