Skip to content

Commit 98ed8e4

Browse files
committed
Merge pull request #47 from ebautistabar/restore
Added restore command
2 parents 3087c52 + b2c075d commit 98ed8e4

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const VERSION = "1.3.2"
1414
var FetchEndpoints = map[string]string{
1515
"current": "/api/v1/user/assignments/current",
1616
"next": "/api/v1/user/assignments/next",
17+
"restore": "/api/v1/user/assignments/restore",
1718
"demo": "/api/v1/assignments/demo",
1819
"exercise": "/api/v1/assignments",
1920
}

main.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,33 @@ func main() {
148148
}
149149
},
150150
},
151+
{
152+
Name: "restore",
153+
ShortName: "r",
154+
Usage: "Restore completed and current assignments from exercism.io",
155+
Action: func(c *cli.Context) {
156+
config, err := configuration.FromFile(configuration.HomeDir())
157+
if err != nil {
158+
fmt.Println("Are you sure you are logged in? Please login again.")
159+
return
160+
}
161+
162+
assignments, err := FetchAssignments(config, FetchEndpoints["restore"])
163+
if err != nil {
164+
fmt.Println(err)
165+
return
166+
}
167+
168+
for _, a := range assignments {
169+
err := SaveAssignment(config.ExercismDirectory, a)
170+
if err != nil {
171+
fmt.Println(err)
172+
}
173+
}
174+
175+
fmt.Printf("Exercises written to %s\n", config.ExercismDirectory)
176+
},
177+
},
151178
{
152179
Name: "submit",
153180
ShortName: "s",

0 commit comments

Comments
 (0)