From 35c43e18529780eb615ab89eb32d269bebc473e4 Mon Sep 17 00:00:00 2001 From: ee7 <45465154+ee7@users.noreply.github.com> Date: Fri, 23 Oct 2020 16:40:01 +0200 Subject: [PATCH] Feature: Add `--trackDir` option With this commit, we can now establish a beginning state by specifying: - a track directory - a problem-specifications directory - the offline mode This allows us to do black-box testing of the release binary, running something like: canonical_data_syncer -t /tmp/python -p /tmp/my_prob_specs --offline and then asserting that the changes made are as expected. Closes: #50 --- README.md | 1 + src/cli.nim | 8 +++++++- src/tracks.nim | 6 +++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 597747f72..e2425cb1c 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ Options: -v, --verbosity The verbosity of output. Allowed values: q[uiet], n[ormal], d[etailed] -p, --probSpecsDir Use this `problem-specifications` directory, rather than cloning temporarily -o, --offline Do not check that the directory specified by `-p, --probSpecsDir` is up-to-date + -t, --trackDir Specify a track directory to use instead of the current directory -h, --help Show this help message and exit --version Show this tool's version information and exit ``` diff --git a/src/cli.nim b/src/cli.nim index 6045f5cbe..72e993a49 100644 --- a/src/cli.nim +++ b/src/cli.nim @@ -18,10 +18,11 @@ type verbosity*: Verbosity probSpecsDir*: Option[string] offline*: bool + trackDir*: Option[string] Opt = enum optExercise, optCheck, optMode, optVerbosity, optProbSpecsDir, optOffline, - optHelp, optVersion + optTrackDir, optHelp, optVersion OptKey = tuple short: string @@ -37,6 +38,7 @@ const ("v", "verbosity"), ("p", "probSpecsDir"), ("o", "offline"), + ("t", "trackDir"), ("h", "help"), ("_", "version"), # No short option for `--version` ] @@ -61,6 +63,7 @@ Options: -{optVerbosity.short}, --{optVerbosity.long} The verbosity of output. Allowed values: q[uiet], n[ormal], d[etailed] -{optProbSpecsDir.short}, --{optProbSpecsDir.long} Use this `problem-specifications` directory, rather than cloning temporarily -{optOffline.short}, --{optOffline.long} Do not check that the directory specified by `-p, --probSpecsDir` is up-to-date + -{optTrackDir.short}, --{optTrackDir.long} Specify a track directory to use instead of the current directory -{optHelp.short}, --{optHelp.long} Show this help message and exit --{optVersion.long} Show this tool's version information and exit""" @@ -146,6 +149,9 @@ proc processCmdLine*: Conf = result.probSpecsDir = some(val) of optOffline.short, optOffline.long: result.offline = true + of optTrackDir.short, optTrackDir.long: + showErrorForMissingVal(kind, key, val) + result.trackDir = some(val) of optHelp.short, optHelp.long: showHelp() of optVersion.short, optVersion.long: diff --git a/src/tracks.nim b/src/tracks.nim index e5b4d03c1..4d343e81f 100644 --- a/src/tracks.nim +++ b/src/tracks.nim @@ -83,5 +83,9 @@ proc findTrackExercises(repo: TrackRepo, conf: Conf): seq[TrackExercise] = result.add(newTrackExercise(repoExercise)) proc findTrackExercises*(conf: Conf): seq[TrackExercise] = - let trackRepo = newTrackRepo() + let trackRepo = + if conf.trackDir.isSome(): + TrackRepo(dir: conf.trackDir.get()) + else: + newTrackRepo() trackRepo.findTrackExercises(conf)