Skip to content

Commit 8d0bdbe

Browse files
authored
Drop team-specific logic from the CLI (#1206)
1 parent 0038ab5 commit 8d0bdbe

File tree

8 files changed

+16
-122
lines changed

8 files changed

+16
-122
lines changed

cmd/download.go

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ type download struct {
135135
token, apibaseurl, workspace string
136136

137137
// optional
138-
track, team string
138+
track string
139139
forceoverwrite bool
140140

141141
payload *downloadPayload
@@ -156,7 +156,6 @@ func newDownload(flags *pflag.FlagSet, usrCfg *viper.Viper) (*download, error) {
156156
if err != nil {
157157
return nil, err
158158
}
159-
d.team, err = flags.GetString("team")
160159
if err != nil {
161160
return nil, err
162161
}
@@ -176,7 +175,7 @@ func newDownload(flags *pflag.FlagSet, usrCfg *viper.Viper) (*download, error) {
176175
if err = d.needsUserConfigValues(); err != nil {
177176
return nil, err
178177
}
179-
if err = d.needsSlugWhenGivenTrackOrTeam(); err != nil {
178+
if err = d.needsSlugWhenGivenTrack(); err != nil {
180179
return nil, err
181180
}
182181

@@ -226,9 +225,6 @@ func (d download) buildQueryParams(url *netURL.URL) {
226225
if d.track != "" {
227226
query.Add("track_id", d.track)
228227
}
229-
if d.team != "" {
230-
query.Add("team_id", d.team)
231-
}
232228
}
233229
url.RawQuery = query.Encode()
234230
}
@@ -256,11 +252,11 @@ func (d download) needsUserConfigValues() error {
256252
return nil
257253
}
258254

259-
// needsSlugWhenGivenTrackOrTeam ensures that track/team arguments are also given with a slug.
260-
// (track/team meaningless when given a uuid).
261-
func (d download) needsSlugWhenGivenTrackOrTeam() error {
262-
if (d.team != "" || d.track != "") && d.slug == "" {
263-
return errors.New("--track or --team requires --exercise (not --uuid)")
255+
// needsSlugWhenGivenTrack ensures that track arguments are also given with a slug.
256+
// (track meaningless when given a uuid).
257+
func (d download) needsSlugWhenGivenTrack() error {
258+
if d.track != "" && d.slug == "" {
259+
return errors.New("--track or requires --exercise (not --uuid)")
264260
}
265261
return nil
266262
}
@@ -269,10 +265,6 @@ type downloadPayload struct {
269265
Solution struct {
270266
ID string `json:"id"`
271267
URL string `json:"url"`
272-
Team struct {
273-
Name string `json:"name"`
274-
Slug string `json:"slug"`
275-
} `json:"team"`
276268
User struct {
277269
Handle string `json:"handle"`
278270
IsRequester bool `json:"is_requester"`
@@ -303,7 +295,6 @@ func (dp downloadPayload) metadata() workspace.ExerciseMetadata {
303295
return workspace.ExerciseMetadata{
304296
AutoApprove: dp.Solution.Exercise.AutoApprove,
305297
Track: dp.Solution.Exercise.Track.ID,
306-
Team: dp.Solution.Team.Slug,
307298
ExerciseSlug: dp.Solution.Exercise.ID,
308299
ID: dp.Solution.ID,
309300
URL: dp.Solution.URL,
@@ -361,7 +352,6 @@ func setupDownloadFlags(flags *pflag.FlagSet) {
361352
flags.StringP("uuid", "u", "", "the solution UUID")
362353
flags.StringP("track", "t", "", "the track ID")
363354
flags.StringP("exercise", "e", "", "the exercise slug")
364-
flags.StringP("team", "T", "", "the team slug")
365355
flags.BoolP("force", "F", false, "overwrite existing exercise directory")
366356
}
367357

cmd/download_test.go

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,14 @@ func TestDownload(t *testing.T) {
160160
expectedDir: filepath.Join("users", "alice"),
161161
flags: map[string]string{"uuid": "bogus-id"},
162162
},
163-
{
164-
requester: true,
165-
expectedDir: filepath.Join("teams", "bogus-team"),
166-
flags: map[string]string{"exercise": "bogus-exercise", "track": "bogus-track", "team": "bogus-team"},
167-
},
168163
}
169164

170165
for _, tc := range testCases {
171166
tmpDir, err := os.MkdirTemp("", "download-cmd")
172167
defer os.RemoveAll(tmpDir)
173168
assert.NoError(t, err)
174169

175-
ts := fakeDownloadServer(strconv.FormatBool(tc.requester), tc.flags["team"])
170+
ts := fakeDownloadServer(strconv.FormatBool(tc.requester))
176171
defer ts.Close()
177172

178173
v := viper.New()
@@ -221,10 +216,6 @@ func TestDownloadToExistingDirectory(t *testing.T) {
221216
exerciseDir: filepath.Join("bogus-track", "bogus-exercise"),
222217
flags: map[string]string{"exercise": "bogus-exercise", "track": "bogus-track"},
223218
},
224-
{
225-
exerciseDir: filepath.Join("teams", "bogus-team", "bogus-track", "bogus-exercise"),
226-
flags: map[string]string{"exercise": "bogus-exercise", "track": "bogus-track", "team": "bogus-team"},
227-
},
228219
}
229220

230221
for _, tc := range testCases {
@@ -235,7 +226,7 @@ func TestDownloadToExistingDirectory(t *testing.T) {
235226
err = os.MkdirAll(filepath.Join(tmpDir, tc.exerciseDir), os.FileMode(0755))
236227
assert.NoError(t, err)
237228

238-
ts := fakeDownloadServer("true", "")
229+
ts := fakeDownloadServer("true")
239230
defer ts.Close()
240231

241232
v := viper.New()
@@ -273,10 +264,6 @@ func TestDownloadToExistingDirectoryWithForce(t *testing.T) {
273264
exerciseDir: filepath.Join("bogus-track", "bogus-exercise"),
274265
flags: map[string]string{"exercise": "bogus-exercise", "track": "bogus-track"},
275266
},
276-
{
277-
exerciseDir: filepath.Join("teams", "bogus-team", "bogus-track", "bogus-exercise"),
278-
flags: map[string]string{"exercise": "bogus-exercise", "track": "bogus-track", "team": "bogus-team"},
279-
},
280267
}
281268

282269
for _, tc := range testCases {
@@ -287,7 +274,7 @@ func TestDownloadToExistingDirectoryWithForce(t *testing.T) {
287274
err = os.MkdirAll(filepath.Join(tmpDir, tc.exerciseDir), os.FileMode(0755))
288275
assert.NoError(t, err)
289276

290-
ts := fakeDownloadServer("true", "")
277+
ts := fakeDownloadServer("true")
291278
defer ts.Close()
292279

293280
v := viper.New()
@@ -310,7 +297,7 @@ func TestDownloadToExistingDirectoryWithForce(t *testing.T) {
310297
}
311298
}
312299

313-
func fakeDownloadServer(requestor, teamSlug string) *httptest.Server {
300+
func fakeDownloadServer(requestor string) *httptest.Server {
314301
mux := http.NewServeMux()
315302
server := httptest.NewServer(mux)
316303

@@ -327,15 +314,11 @@ func fakeDownloadServer(requestor, teamSlug string) *httptest.Server {
327314
})
328315

329316
mux.HandleFunc("/solutions/latest", func(w http.ResponseWriter, r *http.Request) {
330-
team := "null"
331-
if teamSlug := r.FormValue("team_id"); teamSlug != "" {
332-
team = fmt.Sprintf(`{"name": "Bogus Team", "slug": "%s"}`, teamSlug)
333-
}
334-
payloadBody := fmt.Sprintf(payloadTemplate, requestor, team, server.URL+"/")
317+
payloadBody := fmt.Sprintf(payloadTemplate, requestor, server.URL+"/")
335318
fmt.Fprint(w, payloadBody)
336319
})
337320
mux.HandleFunc("/solutions/bogus-id", func(w http.ResponseWriter, r *http.Request) {
338-
payloadBody := fmt.Sprintf(payloadTemplate, requestor, "null", server.URL+"/")
321+
payloadBody := fmt.Sprintf(payloadTemplate, requestor, server.URL+"/")
339322
fmt.Fprint(w, payloadBody)
340323
})
341324

@@ -415,7 +398,6 @@ const payloadTemplate = `
415398
"handle": "alice",
416399
"is_requester": %s
417400
},
418-
"team": %s,
419401
"exercise": {
420402
"id": "bogus-exercise",
421403
"instructions_url": "http://example.com/bogus-exercise",

cmd/submit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ func (s *submitCmdContext) printResult(metadata *workspace.ExerciseMetadata) {
312312
%s
313313
`
314314
suffix := "View it at:\n\n "
315-
if metadata.AutoApprove && metadata.Team == "" {
315+
if metadata.AutoApprove {
316316
suffix = "You can complete the exercise and unlock the next core exercise at:\n"
317317
}
318318
fmt.Fprintf(Err, msg, suffix)

cmd/submit_test.go

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -425,53 +425,6 @@ func TestSubmitWithEnormousFile(t *testing.T) {
425425
}
426426
}
427427

428-
func TestSubmitFilesForTeamExercise(t *testing.T) {
429-
co := newCapturedOutput()
430-
co.override()
431-
defer co.reset()
432-
433-
// The fake endpoint will populate this when it receives the call from the command.
434-
submittedFiles := map[string]string{}
435-
ts := fakeSubmitServer(t, submittedFiles)
436-
defer ts.Close()
437-
438-
tmpDir, err := os.MkdirTemp("", "submit-files")
439-
assert.NoError(t, err)
440-
441-
dir := filepath.Join(tmpDir, "teams", "bogus-team", "bogus-track", "bogus-exercise")
442-
os.MkdirAll(filepath.Join(dir, "subdir"), os.FileMode(0755))
443-
writeFakeMetadata(t, dir, "bogus-track", "bogus-exercise")
444-
445-
file1 := filepath.Join(dir, "file-1.txt")
446-
err = os.WriteFile(file1, []byte("This is file 1."), os.FileMode(0755))
447-
assert.NoError(t, err)
448-
449-
file2 := filepath.Join(dir, "subdir", "file-2.txt")
450-
err = os.WriteFile(file2, []byte("This is file 2."), os.FileMode(0755))
451-
assert.NoError(t, err)
452-
453-
v := viper.New()
454-
v.Set("token", "abc123")
455-
v.Set("workspace", tmpDir)
456-
v.Set("apibaseurl", ts.URL)
457-
458-
cfg := config.Config{
459-
Dir: tmpDir,
460-
UserViperConfig: v,
461-
}
462-
463-
files := []string{
464-
file1, file2,
465-
}
466-
err = runSubmit(cfg, pflag.NewFlagSet("fake", pflag.PanicOnError), files)
467-
assert.NoError(t, err)
468-
469-
assert.Equal(t, 2, len(submittedFiles))
470-
471-
assert.Equal(t, "This is file 1.", submittedFiles["file-1.txt"])
472-
assert.Equal(t, "This is file 2.", submittedFiles["subdir/file-2.txt"])
473-
}
474-
475428
func TestSubmitOnlyEmptyFile(t *testing.T) {
476429
co := newCapturedOutput()
477430
co.override()

shell/exercism.fish

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ complete -f -c exercism -n "__fish_seen_subcommand_from configure" -s s -l show
99
complete -f -c exercism -n "__fish_use_subcommand" -a "download" -d "Downloads and saves a specified submission into the local system"
1010
complete -f -c exercism -n "__fish_seen_subcommand_from download" -s e -l exercise -d "the exercise slug"
1111
complete -f -c exercism -n "__fish_seen_subcommand_from download" -s h -l help -d "help for download"
12-
complete -f -c exercism -n "__fish_seen_subcommand_from download" -s T -l team -d "the team slug"
1312
complete -f -c exercism -n "__fish_seen_subcommand_from download" -s t -l track -d "the track ID"
1413
complete -f -c exercism -n "__fish_seen_subcommand_from download" -s u -l uuid -d "the solution UUID"
1514

workspace/exercise_metadata.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ type ExerciseMetadata struct {
2020
Track string `json:"track"`
2121
ExerciseSlug string `json:"exercise"`
2222
ID string `json:"id"`
23-
Team string `json:"team,omitempty"`
2423
URL string `json:"url"`
2524
Handle string `json:"handle"`
2625
IsRequester bool `json:"is_requester"`
@@ -98,9 +97,6 @@ func (em *ExerciseMetadata) Exercise(workspace string) Exercise {
9897

9998
// root represents the root of the exercise.
10099
func (em *ExerciseMetadata) root(workspace string) string {
101-
if em.Team != "" {
102-
return filepath.Join(workspace, "teams", em.Team)
103-
}
104100
if !em.IsRequester {
105101
return filepath.Join(workspace, "users", em.Handle)
106102
}

workspace/workspace.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -58,28 +58,6 @@ func (ws Workspace) PotentialExercises() ([]Exercise, error) {
5858
continue
5959
}
6060

61-
if topInfo.Name() == "teams" {
62-
subInfos, err := os.ReadDir(filepath.Join(ws.Dir, "teams"))
63-
if err != nil {
64-
return nil, err
65-
}
66-
67-
for _, subInfo := range subInfos {
68-
teamWs, err := New(filepath.Join(ws.Dir, "teams", subInfo.Name()))
69-
if err != nil {
70-
return nil, err
71-
}
72-
73-
teamExercises, err := teamWs.PotentialExercises()
74-
if err != nil {
75-
return nil, err
76-
}
77-
78-
exercises = append(exercises, teamExercises...)
79-
}
80-
continue
81-
}
82-
8361
subInfos, err := os.ReadDir(filepath.Join(ws.Dir, topInfo.Name()))
8462
if err != nil {
8563
return nil, err

workspace/workspace_test.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,13 @@ func TestWorkspacePotentialExercises(t *testing.T) {
1919
b1 := filepath.Join(tmpDir, "track-b", "exercise-one")
2020
b2 := filepath.Join(tmpDir, "track-b", "exercise-two")
2121

22-
// It should find teams exercises
23-
team := filepath.Join(tmpDir, "teams", "some-team", "track-c", "exercise-one")
24-
2522
// It should ignore other people's exercises.
2623
alice := filepath.Join(tmpDir, "users", "alice", "track-a", "exercise-one")
2724

2825
// It should ignore nested dirs within exercises.
2926
nested := filepath.Join(a1, "subdir", "deeper-dir", "another-deep-dir")
3027

31-
for _, path := range []string{a1, b1, b2, team, alice, nested} {
28+
for _, path := range []string{a1, b1, b2, alice, nested} {
3229
err := os.MkdirAll(path, os.FileMode(0755))
3330
assert.NoError(t, err)
3431
}
@@ -38,7 +35,7 @@ func TestWorkspacePotentialExercises(t *testing.T) {
3835

3936
exercises, err := ws.PotentialExercises()
4037
assert.NoError(t, err)
41-
if assert.Equal(t, 4, len(exercises)) {
38+
if assert.Equal(t, 3, len(exercises)) {
4239
paths := make([]string, len(exercises))
4340
for i, e := range exercises {
4441
paths[i] = e.Path()
@@ -48,7 +45,6 @@ func TestWorkspacePotentialExercises(t *testing.T) {
4845
assert.Equal(t, paths[0], "track-a/exercise-one")
4946
assert.Equal(t, paths[1], "track-b/exercise-one")
5047
assert.Equal(t, paths[2], "track-b/exercise-two")
51-
assert.Equal(t, paths[3], "track-c/exercise-one")
5248
}
5349
}
5450

0 commit comments

Comments
 (0)