Skip to content

Commit

Permalink
cli: add --track-dir option
Browse files Browse the repository at this point in the history
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:
    configlet -t /tmp/python -p /tmp/my_prob_specs --offline
and then asserting that the changes made are as expected.

Closes: exercism#50
  • Loading branch information
ee7 committed Jan 26, 2021
1 parent 21712d0 commit 47ce56b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Options for uuid:
Global options:
-h, --help Show this help message and exit
--version Show this tool's version information and exit
-t, --track-dir <dir> Specify a track directory to use instead of the current directory
-v, --verbosity <verbosity> The verbosity of output. Allowed values: q[uiet], n[ormal], d[etailed]
```

Expand Down
6 changes: 6 additions & 0 deletions src/cli.nim
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ type

Conf* = object
action*: Action
trackDir*: string
verbosity*: Verbosity

Opt = enum
optHelp = "help"
optVersion = "version"
optTrackDir = "trackDir"
optVerbosity = "verbosity"
optSyncExercise = "exercise"
optSyncCheck = "check"
Expand Down Expand Up @@ -110,6 +112,7 @@ func genHelpText: string =
for opt in Opt:
let paramName =
case opt
of optTrackDir: "dir"
of optVerbosity: "verbosity"
of optSyncExercise: "slug"
of optSyncMode: "mode"
Expand All @@ -127,6 +130,7 @@ func genHelpText: string =
const descriptions: array[Opt, string] = [
optHelp: "Show this help message and exit",
optVersion: "Show this tool's version information and exit",
optTrackDir: "Specify a track directory to use instead of the current directory",
optVerbosity: &"The verbosity of output. {allowedValues(Verbosity)}",
optSyncExercise: "Only sync this exercise",
optSyncCheck: "Terminates with a non-zero exit code if one or more tests " &
Expand Down Expand Up @@ -310,6 +314,8 @@ proc handleOption(conf: var Conf; kind: CmdLineKind; key, val: string) =
showHelp()
of optVersion:
showVersion()
of optTrackDir:
setGlobalOpt(trackDir, val)
of optVerbosity:
setGlobalOpt(verbosity, parseVal[Verbosity](kind, key, val))
else:
Expand Down
6 changes: 5 additions & 1 deletion src/sync/tracks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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.len > 0:
TrackRepo(dir: conf.trackDir)
else:
newTrackRepo()
trackRepo.findTrackExercises(conf)

0 comments on commit 47ce56b

Please sign in to comment.