Skip to content

Commit

Permalink
Move to exercise method
Browse files Browse the repository at this point in the history
  • Loading branch information
jdsutherland committed Jan 2, 2019
1 parent 4a392b8 commit 0dc46fb
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions cmd/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,11 @@ func runSubmit(cfg config.Config, flags *pflag.FlagSet, args []string) error {
return err
}

exerciseDir, err := ctx.exerciseDir()
exercise, err := ctx.exercise()
if err != nil {
return err
}

exercise := workspace.NewExerciseFromDir(exerciseDir)

migrationStatus, err := exercise.MigrateLegacyMetadataFile()
if err != nil {
return err
Expand All @@ -83,12 +81,12 @@ func runSubmit(cfg config.Config, flags *pflag.FlagSet, args []string) error {
fmt.Fprintf(Err, migrationStatus.String())
}

metadata, err := ctx.metadata(exerciseDir)
metadata, err := ctx.metadata(exercise.Filepath())
if err != nil {
return err
}

exercise.Documents, err = ctx.documents(exerciseDir)
exercise.Documents, err = ctx.documents(exercise.Filepath())
if err != nil {
return err
}
Expand Down Expand Up @@ -157,20 +155,20 @@ func (ctx *submitContext) sanitizeArgs() error {
return nil
}

func (ctx *submitContext) exerciseDir() (string, error) {
func (ctx *submitContext) exercise() (workspace.Exercise, error) {
ws, err := workspace.New(ctx.usrCfg.GetString("workspace"))
if err != nil {
return "", err
return workspace.Exercise{}, err
}

var exerciseDir string
for _, arg := range ctx.args {
dir, err := ws.ExerciseDir(arg)
if err != nil {
if workspace.IsMissingMetadata(err) {
return "", errors.New(msgMissingMetadata)
return workspace.Exercise{}, errors.New(msgMissingMetadata)
}
return "", err
return workspace.Exercise{}, err
}
if exerciseDir != "" && dir != exerciseDir {
msg := `
Expand All @@ -179,11 +177,12 @@ func (ctx *submitContext) exerciseDir() (string, error) {
Please submit the files for one solution at a time.
`
return "", errors.New(msg)
return workspace.Exercise{}, errors.New(msg)
}
exerciseDir = dir
}
return exerciseDir, nil

return workspace.NewExerciseFromDir(exerciseDir), nil
}

func (ctx *submitContext) metadata(exerciseDir string) (*workspace.ExerciseMetadata, error) {
Expand Down

0 comments on commit 0dc46fb

Please sign in to comment.