-
-
Notifications
You must be signed in to change notification settings - Fork 368
Add '--all' flag to 'fetch' command #336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
|
||
| 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) | ||
| } | ||
|
|
@@ -71,3 +82,20 @@ func setSubmissionState(problems []*api.Problem, submissionInfo map[string][]api | |
|
|
||
| return nil | ||
| } | ||
|
|
||
| func fetchAll(trackID string, client *api.Client) []*api.Problem { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Also, what do you think about adding this to the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| } | ||
There was a problem hiding this comment.
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
allflag is set to true. What if we moved it to theelseof the followingif?