Skip to content

Commit b268ce8

Browse files
author
Katrina Owen
committed
Implement team flag for download command
1 parent 8efce13 commit b268ce8

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

cmd/download.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,20 @@ func runDownload(cfg config.Configuration, flags *pflag.FlagSet, args []string)
9090
return err
9191
}
9292

93+
team, err := flags.GetString("team")
94+
if err != nil {
95+
return err
96+
}
97+
9398
if uuid == "" {
9499
q := req.URL.Query()
95100
q.Add("exercise_id", exercise)
96101
if track != "" {
97102
q.Add("track_id", track)
98103
}
104+
if team != "" {
105+
q.Add("team_id", team)
106+
}
99107
req.URL.RawQuery = q.Encode()
100108
}
101109

@@ -127,6 +135,7 @@ func runDownload(cfg config.Configuration, flags *pflag.FlagSet, args []string)
127135
solution := workspace.Solution{
128136
AutoApprove: payload.Solution.Exercise.AutoApprove,
129137
Track: payload.Solution.Exercise.Track.ID,
138+
Team: payload.Solution.Team.Slug,
130139
Exercise: payload.Solution.Exercise.ID,
131140
ID: payload.Solution.ID,
132141
URL: payload.Solution.URL,
@@ -135,6 +144,9 @@ func runDownload(cfg config.Configuration, flags *pflag.FlagSet, args []string)
135144
}
136145

137146
dir := usrCfg.GetString("workspace")
147+
if solution.Team != "" {
148+
dir = filepath.Join(dir, "teams", solution.Team)
149+
}
138150
if !solution.IsRequester {
139151
dir = filepath.Join(dir, "users", solution.Handle)
140152
}
@@ -205,6 +217,10 @@ type downloadPayload struct {
205217
Solution struct {
206218
ID string `json:"id"`
207219
URL string `json:"url"`
220+
Team struct {
221+
Name string `json:"name"`
222+
Slug string `json:"slug"`
223+
} `json:"team"`
208224
User struct {
209225
Handle string `json:"handle"`
210226
IsRequester bool `json:"is_requester"`
@@ -235,6 +251,7 @@ func setupDownloadFlags(flags *pflag.FlagSet) {
235251
flags.StringP("uuid", "u", "", "the solution UUID")
236252
flags.StringP("track", "t", "", "the track ID")
237253
flags.StringP("exercise", "e", "", "the exercise slug")
254+
flags.StringP("team", "T", "", "the team slug")
238255
}
239256

240257
func init() {

cmd/download_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ func TestDownload(t *testing.T) {
107107
expectedDir: filepath.Join("users", "alice"),
108108
flags: map[string]string{"uuid": "bogus-id"},
109109
},
110+
{
111+
requester: true,
112+
expectedDir: filepath.Join("teams", "bogus-team"),
113+
flags: map[string]string{"exercise": "bogus-exercise", "track": "bogus-track", "team": "bogus-team"},
114+
},
110115
}
111116

112117
for _, tc := range testCases {

0 commit comments

Comments
 (0)