-
-
Notifications
You must be signed in to change notification settings - Fork 369
Expand file tree
/
Copy pathlist.go
More file actions
42 lines (35 loc) · 913 Bytes
/
list.go
File metadata and controls
42 lines (35 loc) · 913 Bytes
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
package cmd
import (
"fmt"
"log"
"github.com/codegangsta/cli"
"github.com/exercism/cli/api"
"github.com/exercism/cli/config"
)
const msgExplainFetch = "In order to fetch a specific assignment, call the fetch command with a specific assignment.\n\nexercism fetch %s %s\n\n"
// List returns the full list of assignments for a given track.
func List(ctx *cli.Context) {
c, err := config.New(ctx.GlobalString("config"))
if err != nil {
log.Fatal(err)
}
args := ctx.Args()
if len(args) != 1 {
msg := "Usage: exercism list TRACK_ID"
log.Fatal(msg)
}
trackID := args[0]
client := api.NewClient(c)
problems, err := client.List(trackID)
if err != nil {
if err == api.ErrUnknownTrack {
log.Fatalf("There is no track with ID '%s'.", trackID)
}
log.Fatal(err)
}
for _, p := range problems {
fmt.Printf("%s\n", p)
}
fmt.Println()
fmt.Printf(msgExplainFetch, trackID, problems[0])
}