-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
60 lines (48 loc) · 1.3 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
55
56
57
58
59
60
package main
import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"log"
"github.com/johnhany97/grader/grader"
"github.com/johnhany97/grader/test"
)
const maxTasks = 10
func main() {
// Parse arguments to application
schemaFile := flag.String("schema", "", "Marking scheme to follow when grading the assignment (required)")
flag.Parse()
if *schemaFile == "" {
fmt.Println("Missing arguments, please make sure to provide all required arguments.")
return
}
schema := grader.Schema{}
// read schema file
schemaFileContent, err := ioutil.ReadFile(*schemaFile)
if err != nil {
log.Fatal(err)
}
// unmarshal unto the schema var
err = json.Unmarshal(schemaFileContent, &schema)
if err != nil {
log.Fatal(err)
}
grader := grader.NewGrader(schema, maxTasks)
// Run Grader
testResults := grader.Grade()
// Process test results as requested in schema
processResults(testResults, schema.Outfile, schema.Folder)
}
// processResults is used to marshal the test results unto a JSON
// and print it out to the terminal or store it in the outfile if specified
func processResults(tr []test.Result, outfile string, folder string) {
bs, _ := json.Marshal(tr)
if outfile == "" {
fmt.Println(string(bs))
} else {
if err := ioutil.WriteFile(folder+outfile, bs, 0644); err != nil {
log.Fatal(err)
}
}
}