MCPcopy Create free account
hub / github.com/exercism/cli / PotentialExercises

Method PotentialExercises

workspace/workspace.go:45–76  ·  view source on GitHub ↗

PotentialExercises are a first-level guess at the user's exercises. It looks at the workspace structurally, and guesses based on the location of the directory. E.g. any top level directory within the workspace (except 'users') is assumed to be a track, and any directory within there again is assumed

()

Source from the content-addressed store, hash-verified

43// track, and any directory within there again is assumed to
44// be an exercise.
45func (ws Workspace) PotentialExercises() ([]Exercise, error) {
46 exercises := []Exercise{}
47
48 topInfos, err := os.ReadDir(ws.Dir)
49 if err != nil {
50 return nil, err
51 }
52 for _, topInfo := range topInfos {
53 if !topInfo.IsDir() {
54 continue
55 }
56
57 if topInfo.Name() == "users" {
58 continue
59 }
60
61 subInfos, err := os.ReadDir(filepath.Join(ws.Dir, topInfo.Name()))
62 if err != nil {
63 return nil, err
64 }
65
66 for _, subInfo := range subInfos {
67 if !subInfo.IsDir() {
68 continue
69 }
70
71 exercises = append(exercises, Exercise{Track: topInfo.Name(), Slug: subInfo.Name(), Root: ws.Dir})
72 }
73 }
74
75 return exercises, nil
76}
77
78// Exercises returns the user's exercises within the workspace.
79// This doesn't find legacy exercises where the metadata is missing.

Callers 2

ExercisesMethod · 0.95

Calls

no outgoing calls

Tested by 1