-
Notifications
You must be signed in to change notification settings - Fork 6
/
exercises-cli.go
57 lines (47 loc) · 1.06 KB
/
exercises-cli.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
//go:build ignore
package main
import (
"flag"
"fmt"
"log"
"os"
"github.com/l7mp/learning-go/internals/lib"
)
func Usage() {
fmt.Fprintf(os.Stderr, "exercises-cli <generate|check>\n")
fmt.Fprintf(os.Stderr, "Flags:\n")
flag.PrintDefaults()
}
var (
studentId = flag.String("student-id", "", "student id; optional, default is to read from file STUDENT_ID")
verbose = flag.Bool("verbose", false, "verbose mode; default is off")
)
func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
// log.SetFlags(0)
log.SetPrefix("exercises-cli: ")
flag.Usage = Usage
flag.Parse()
if len(flag.Args()) != 1 {
flag.Usage()
os.Exit(1)
}
id, err := lib.GetStudentId(studentId)
if err != nil {
log.Fatalf("Cannot find student id: %s", err)
}
if *verbose {
log.Printf("Using student id %q\n", id)
}
switch flag.Arg(0) {
case "generate":
if err := lib.Generate(id, *verbose); err != nil {
log.Fatalf("Cannot generate exercise for student id %q: %s", id, err)
}
case "check":
fmt.Println("Would check stuff")
default:
flag.Usage()
os.Exit(1)
}
}