Skip to content

Commit a3c2bce

Browse files
committed
exercise has tacit dep on filesBelongToSameExercise
exercise() uses ws.ExerciseDir() to find the root dir of an exercise. Since ws.ExerciseDir requires a single path, this tacitly assumes that the submitted paths are all part of the same exercise. There is a validation for this called `filesBelongToSameExercise`. This isn't an issue from the point of view of `runSubmit` but it might be an issue if `exercise()` gets moved around in the future as this isn't explicitly stated. These changes attempt to make it more clear by stating it in the godoc.
1 parent 3023109 commit a3c2bce

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

cmd/submit.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func runSubmit(cfg config.Config, flags *pflag.FlagSet, args []string) error {
7070
return err
7171
}
7272

73-
exercise, err := ctx.exercise(submitPaths)
73+
exercise, err := ctx.exercise(submitPaths[0])
7474
if err != nil {
7575
return err
7676
}
@@ -146,14 +146,15 @@ func (s *submitCmdContext) evaluatedSymlinks(submitPaths []string) ([]string, er
146146
return evalSymlinkSubmitPaths, nil
147147
}
148148

149-
// exercise returns an Exercise using the directory of the submitted paths.
150-
func (s *submitCmdContext) exercise(submitPaths []string) (workspace.Exercise, error) {
149+
// exercise creates an exercise using one of the submitted filepaths.
150+
// This assumes prior verification that submit paths belong to the same exercise.
151+
func (s *submitCmdContext) exercise(aSubmitPath string) (workspace.Exercise, error) {
151152
ws, err := workspace.New(s.usrCfg.GetString("workspace"))
152153
if err != nil {
153154
return workspace.Exercise{}, err
154155
}
155156

156-
dir, err := ws.ExerciseDir(submitPaths[0])
157+
dir, err := ws.ExerciseDir(aSubmitPath)
157158
if err != nil {
158159
return workspace.Exercise{}, err
159160
}

0 commit comments

Comments
 (0)