forked from blinry/nutsh
-
Notifications
You must be signed in to change notification settings - Fork 1
/
nutsh.go
75 lines (68 loc) · 1.31 KB
/
nutsh.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"fmt"
"os"
//"io/ioutil"
"github.com/tubs-ips/nutsh/model"
"github.com/tubs-ips/nutsh/parser"
)
func main() {
if len(os.Args) < 3 {
fmt.Println("Usage: nutsh (run|test) <tutorial dir> [lesson name]")
}
command := os.Args[1]
dir := os.Args[2]
lesson_name := ""
done := false
if len(os.Args) > 3 {
lesson_name = os.Args[3]
}
tut := model.Init(dir)
switch command {
case "run":
var l *model.Lesson
var exists bool
var ok bool
if lesson_name != "" {
l, exists = tut.Lessons[lesson_name]
if ! exists {
lesson_name = ""
}
}
if lesson_name == "" {
lesson_name, ok = tut.SelectLesson(false)
if ! ok {
break
}
}
for {
l, _ = tut.Lessons[lesson_name]
lesson_name, done = parser.Interpret(l.Root, tut.Common)
if done {
l.Done = true
tut.SaveProgress()
}
if lesson_name != "" {
l, exists = tut.Lessons[lesson_name]
if exists {
continue
}
}
lesson_name, ok = tut.SelectLesson(false)
if ! ok {
break
}
}
case "test":
if lesson_name != "" {
l, _ := tut.Lessons[lesson_name]
parser.Test(l.Root, tut.Common)
fmt.Println("\""+parser.GetName(l.Root)+"\""+" passed.")
} else {
for _, l := range tut.Lessons {
parser.Test(l.Root, tut.Common)
}
fmt.Println("All lessons passed!")
}
}
}