-
-
Notifications
You must be signed in to change notification settings - Fork 369
Expand file tree
/
Copy pathfetch.go
More file actions
73 lines (59 loc) · 1.42 KB
/
fetch.go
File metadata and controls
73 lines (59 loc) · 1.42 KB
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
package cmd
import (
"log"
"path/filepath"
"github.com/codegangsta/cli"
"github.com/exercism/cli/api"
"github.com/exercism/cli/config"
"github.com/exercism/cli/user"
)
// Fetch downloads exercism problems and writes them to disk.
func Fetch(ctx *cli.Context) error {
c, err := config.New(ctx.GlobalString("config"))
if err != nil {
log.Fatal(err)
}
client := api.NewClient(c)
problems, err := client.Fetch(ctx.Args())
if err != nil {
log.Fatal(err)
}
submissionInfo, err := client.Submissions()
if err != nil {
log.Fatal(err)
}
if err := setSubmissionState(problems, submissionInfo); err != nil {
log.Fatal(err)
}
dirs, err := filepath.Glob(filepath.Join(c.Dir, "*"))
if err != nil {
log.Fatal(err)
}
dirMap := make(map[string]bool)
for _, dir := range dirs {
dirMap[dir] = true
}
hw := user.NewHomework(problems, c)
if len(ctx.Args()) == 0 {
if err := hw.RejectMissingTracks(dirMap); err != nil {
log.Fatal(err)
}
}
if err := hw.Save(); err != nil {
log.Fatal(err)
}
hw.Summarize(user.HWAll)
return nil
// return cli.NewExitError("no good", 10)
}
func setSubmissionState(problems []*api.Problem, submissionInfo map[string][]api.SubmissionInfo) error {
for _, problem := range problems {
langSubmissions := submissionInfo[problem.TrackID]
for _, submission := range langSubmissions {
if submission.Slug == problem.Slug {
problem.Submitted = true
}
}
}
return nil
}