Skip to content

Commit

Permalink
initial work to update track config
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSchierboom committed Dec 19, 2023
1 parent 87d531f commit 7a31e8f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
40 changes: 36 additions & 4 deletions src/create/exercises.nim
Original file line number Diff line number Diff line change
@@ -1,9 +1,41 @@
import std/[os, strformat]
import ".."/[cli, helpers, sync/sync, types_track_config]
import "."/[approaches, articles]
import std/[sets, os, strformat]
import ".."/[cli, helpers, fmt/track_config, sync/sync, types_track_config, uuid/uuid]

proc createConceptExercise*(conf: Conf) =
echo "create ce"

proc createPracticeExercise*(conf: Conf) =
echo "create pe"
let trackConfigPath = conf.trackDir / "config.json"
let trackConfig = parseFile(trackConfigPath, TrackConfig)
let trackExerciseSlugs = getSlugs(trackConfig.exercises, conf, trackConfigPath)
let userExercise = Slug(conf.action.exerciseCreate)

if userExercise in trackExerciseSlugs.`concept`:
let msg = &"There already is a concept exercise with `{userExercise}` " &
&"in the track config:\n{trackConfigPath}"
stderr.writeLine msg
quit 1
elif userExercise in trackExerciseSlugs.practice:
let msg = &"There already is a practice exercise with `{userExercise}` " &
&"in the track config:\n{trackConfigPath}"
stderr.writeLine msg
quit 1

let exerciseDir = conf.trackDir / "exercises" / "practice" / $userExercise
let exercise = PracticeExercise(
slug: userExercise,
name: $userExercise,
uuid: $genUuid(),
practices: OrderedSet[string](),
prerequisites: OrderedSet[string](),
difficulty: 1,
status: sMissing
)

var a = trackConfig.exercises.practice
a.add(exercise)

trackConfig.exercises.practice = a;

let prettied = prettyTrackConfig(trackConfig)
writeFile(trackConfigPath, prettied)
2 changes: 1 addition & 1 deletion src/fmt/track_config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func addConcepts(result: var string; val: Concepts; indentLevel = 1) =
result.addNewlineAndIndent(indentLevel)
result.add "],"

func prettyTrackConfig(e: TrackConfig): string =
func prettyTrackConfig*(e: TrackConfig): string =
## Serializes `e` as pretty-printed JSON, using the canonical key order.
let keys = trackConfigKeyOrderForFmt(e)

Expand Down

0 comments on commit 7a31e8f

Please sign in to comment.