Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion cmd/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,18 @@ func Fetch(ctx *cli.Context) error {
}
client := api.NewClient(c)

problems, err := client.Fetch(ctx.Args())
args := ctx.Args()
problems, err := client.Fetch(args)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't perform this fetch if the all flag is set to true. What if we moved it to the else of the following if?


if ctx.Bool("all") {
if len(args) > 0 {
trackID := args[0]
problems = fetchAll(trackID, client)
} else {
log.Fatalf("You must supply a track to fetch all exercises")
}
}

if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -71,3 +82,20 @@ func setSubmissionState(problems []*api.Problem, submissionInfo map[string][]api

return nil
}

func fetchAll(trackID string, client *api.Client) []*api.Problem {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we make it so that this function returns the list of problems and the error and log.Fatal on the caller if the error is not nil?

Also, what do you think about adding this to the api.Client in case we add an API in the future to fetch a list of exercises?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for returning the error from here.

list, err := client.List(trackID)
if err != nil {
log.Fatal(err)
}

problems := make([]*api.Problem, len(list))
for i, prob := range list {
p, err := client.Fetch([]string{trackID, prob})
if err != nil {
log.Fatal(err)
}
problems[i] = p[0]
}
return problems
}
8 changes: 7 additions & 1 deletion exercism/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,13 @@ func main() {
Name: "fetch",
ShortName: "f",
Usage: descFetch,
Action: cmd.Fetch,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "all",
Usage: "fetch all exercises for a given track",
},
},
Action: cmd.Fetch,
},
{
Name: "list",
Expand Down