Skip to content

Commit

Permalink
refactor: use QuitSuccess and QuitFailure in quit calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSchierboom committed Jan 16, 2024
1 parent 0d3e407 commit 8a3fdcb
Show file tree
Hide file tree
Showing 19 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion bin/bump_version.nim
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ proc main =
except BumpError:
let msg = getCurrentExceptionMsg()
stderr.writeLine &"Error: {msg}"
quit 1
quit(QuitFailure)

when isMainModule:
main()
2 changes: 1 addition & 1 deletion bin/tag_release.nim
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ proc main =
except BumpError:
let msg = getCurrentExceptionMsg()
stderr.writeLine &"Error: {msg}"
quit 1
quit(QuitFailure)

when isMainModule:
main()
4 changes: 2 additions & 2 deletions src/cli.nim
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ proc showHelp(exitCode: range[0..255] = 0, prependDashedLine = false) =

proc showVersion =
echo &"{configletVersion}"
quit(0)
quit(QuitSuccess)

proc shouldUseColor(f: File): bool =
## Returns true if we should write to `f` with color.
Expand All @@ -359,7 +359,7 @@ proc showError*(s: string, writeHelp = true) =
if writeHelp:
showHelp(exitCode = 1, prependDashedLine = true)
else:
quit 1
quit(QuitFailure)

func formatOpt(kind: CmdLineKind, key: string, val = ""): string =
## Returns a string that describes an option, given its `kind`, `key` and
Expand Down
2 changes: 1 addition & 1 deletion src/configlet.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "."/[cli, completion/completion, create/create, fmt/fmt, info/info,

proc configlet =
onSignal(SIGTERM):
quit(0)
quit(QuitSuccess)

let conf = processCmdLine()

Expand Down
12 changes: 6 additions & 6 deletions src/create/create.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ proc create*(conf: Conf) =
if conf.action.exerciseCreate.len == 0:
let msg = "Please specify an exercise, using --exercise <slug>"
stderr.writeLine msg
quit 1
quit(QuitFailure)
if conf.action.approachSlug.len > 0:
if conf.action.articleSlug.len > 0:
let msg = &"Both --approach and --article were provided. Please specify only one."
stderr.writeLine msg
quit 1
quit(QuitFailure)
let trackConfigPath = conf.trackDir / "config.json"
let trackConfig = parseFile(trackConfigPath, TrackConfig)
let trackExerciseSlugs = getSlugs(trackConfig.exercises, conf, trackConfigPath)
Expand All @@ -28,7 +28,7 @@ proc create*(conf: Conf) =
&"exercise slug, but `{userExercise}` is not an slug in the " &
&"track config:\n{trackConfigPath}"
stderr.writeLine msg
quit 1
quit(QuitFailure)

createApproach(Slug(conf.action.approachSlug), userExercise, exerciseDir)
elif conf.action.articleSlug.len > 0:
Expand All @@ -47,12 +47,12 @@ proc create*(conf: Conf) =
&"exercise slug, but `{userExercise}` is not an slug in the " &
&"track config:\n{trackConfigPath}"
stderr.writeLine msg
quit 1
quit(QuitFailure)

createArticle(Slug(conf.action.articleSlug), userExercise, exerciseDir)
else:
let msg = "Please specify `--article <slug>` or `--approach <slug>`"
stderr.writeLine msg
quit 1
quit(QuitFailure)
else:
quit 1
quit(QuitFailure)
2 changes: 1 addition & 1 deletion src/exec.nim
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ proc cloneExercismRepo*(repoName, dest: string; shallow = false;
else:
stderr.writeLine "failure"
stderr.writeLine outp
quit 1
quit(QuitFailure)

proc gitCheckout(dir, hash: string) =
## Checkout `hash` in the git repo at `dir`, discarding changes to the working
Expand Down
2 changes: 1 addition & 1 deletion src/fmt/exercises.nim
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ proc addObject(s: var string; key: string; val: JsonNode; indentLevel = 1) =
else:
stderr.writeLine &"The value of a `{key}` key is not a JSON object:"
stderr.writeLine val.pretty()
quit 1
quit(QuitFailure)

func exerciseConfigKeyOrderForSync(originalKeyOrder: seq[
ExerciseConfigKey]): seq[ExerciseConfigKey] =
Expand Down
4 changes: 2 additions & 2 deletions src/fmt/fmt.nim
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ proc fmt*(conf: Conf) =
if conf.action.yesFmt or userSaysYes(userExercise):
writeFormatted(pairs)
else:
quit 1
quit(QuitFailure)
else:
quit 1
quit(QuitFailure)
else:
let wording =
if userExercise.len > 0:
Expand Down
6 changes: 3 additions & 3 deletions src/generate/generate.nim
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ proc conceptIntroduction(trackDir: Path, slug: Slug, templatePath: Path,
result = path.readFile().alterHeadings(linkDefs, h2)
else:
writeError(&"File {path} not found for concept '{slug}'", templatePath)
quit(1)
quit(QuitFailure)
else:
writeError(&"Directory {conceptDir} not found for concept '{slug}'",
templatePath)
quit(1)
quit(QuitFailure)

proc generateIntroduction(trackDir: Path, templatePath: Path,
slugLookup: Table[Slug, string]): string =
Expand Down Expand Up @@ -119,7 +119,7 @@ proc generateIntroduction(trackDir: Path, templatePath: Path,
else:
writeError(&"Concept '{conceptSlug}' does not exist in track config.json",
templatePath)
quit(1)
quit(QuitFailure)
else:
if content.continuesWith("\n#", i):
headingLevel = content.skipWhile({'#'}, i+1)
Expand Down
4 changes: 2 additions & 2 deletions src/helpers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ proc parseFile*(path: string; T: typedesc): T =
except IOError:
let msg = getCurrentExceptionMsg()
stderr.writeLine &"Error: {msg}"
quit 1
quit(QuitFailure)
if contents.len > 0:
try:
contents.fromJson(T)
Expand All @@ -155,6 +155,6 @@ proc parseFile*(path: string; T: typedesc): T =
let details = tidyJsonyMessage(jsonyMsg, contents)
let msg = &"JSON parsing error:\n{path}{details}"
stderr.writeLine msg
quit 1
quit(QuitFailure)
else:
T()
2 changes: 1 addition & 1 deletion src/lint/lint.nim
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ proc lint*(conf: Conf) =
Configlet detected at least one problem.
For more information on resolving the problems, please see the documentation:
{url}""".unindent()
quit(1)
quit(QuitFailure)
4 changes: 2 additions & 2 deletions src/sync/probspecs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@ proc init*(T: typedesc[ProbSpecsDir], conf: Conf): T =
'problem-specifications' elsewhere, you can copy it to the above location and then
use it with --offline.""".unindent()
stderr.writeLine msg
quit 1
quit(QuitFailure)
else:
try:
createDir result.parentDir()
except IOError, OSError:
stderr.writeLine &"Error: {getCurrentExceptionMsg()}"
quit 1
quit(QuitFailure)
cloneExercismRepo("problem-specifications", result.string, shallow = false)
2 changes: 1 addition & 1 deletion src/sync/sync.nim
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ proc getSlugs*(exercises: Exercises, conf: Conf,
&"exercise slug, but `{userExercise}` is not an slug in the " &
&"track config:\n{trackConfigPath}"
stderr.writeLine msg
quit 1
quit(QuitFailure)

proc syncImpl(conf: Conf): set[SyncKind] =
## Checks the data specified in `conf.action.scope`, and updates them if
Expand Down
2 changes: 1 addition & 1 deletion src/sync/sync_common.nim
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ proc postHook*(e: ConceptExercise | PracticeExercise) =
let msg = "Error: the track `config.json` file contains " &
&"an exercise slug of \"{s}\", which is not a kebab-case string"
stderr.writeLine msg
quit 1
quit(QuitFailure)

func getSlugs*(e: seq[ConceptExercise] | seq[PracticeExercise],
withDeprecated = true): seq[Slug] =
Expand Down
2 changes: 1 addition & 1 deletion src/sync/sync_docs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ proc write(pairsToWrite: seq[PathAndContents]) =
writeFile(path, pathAndContents.contents)
else:
stderr.writeLine &"Unexpected path before writing: {path}"
quit 1
quit(QuitFailure)
let s = if pairsToWrite.len > 1: "s" else: ""
logNormal(&"Updated the docs for {pairsToWrite.len} Practice Exercise{s}")

Expand Down
2 changes: 1 addition & 1 deletion src/sync/sync_filepaths.nim
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ proc write(configPairs: seq[PathAndUpdatedExerciseConfig]) =
writeFile(path, contents)
else:
stderr.writeLine &"Unexpected path before writing: {path}"
quit 1
quit(QuitFailure)
let s = if configPairs.len > 1: "s" else: ""
logNormal(&"Updated the filepaths for {configPairs.len} exercise{s}")

Expand Down
2 changes: 1 addition & 1 deletion src/sync/sync_metadata.nim
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ proc write(configPairs: seq[PathAndUpdatedConfig]) =
writeFile(path, updatedJson)
else:
stderr.writeLine &"Unexpected path before writing: {path}"
quit 1
quit(QuitFailure)
let s = if configPairs.len > 1: "s" else: ""
logNormal(&"Updated the metadata for {configPairs.len} Practice Exercise{s}")

Expand Down
8 changes: 4 additions & 4 deletions src/sync/tracks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ proc getPracticeExerciseSlugs(trackDir: TrackDir,
else:
stderr.writeLine "Error: file does not have an `exercises` key:\n" &
configFile
quit(1)
quit(QuitFailure)
else:
stderr.writeLine "Error: file does not exist:\n" & configFile
quit(1)
quit(QuitFailure)

sort result

Expand All @@ -79,10 +79,10 @@ proc init(T: typedesc[PracticeExerciseTests], testsPath: string): T =
The expected 'tests.toml' format is documented in
https://exercism.org/docs/building/configlet/sync#h-tests""".unindent()
quit 1
quit(QuitFailure)
except CatchableError:
stderr.writeLine "Error: " & getCurrentExceptionMsg()
quit 1
quit(QuitFailure)

for uuid, val in tests.getTable():
if val.hasKey("include"):
Expand Down
2 changes: 1 addition & 1 deletion src/uuid/uuid.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ proc genUuid*: Uuid {.noinit.} =
result[8] = (result[8] and 0x3f) or 0x80 # Set variant to 1
else:
stderr.writeLine "uuid: error: failed to read from the system CSPRNG"
quit 1
quit(QuitFailure)

func `$`*(u: Uuid): string =
## Returns the canonical string representation for the given UUID `u`.
Expand Down

0 comments on commit 8a3fdcb

Please sign in to comment.