Fix using --stdout with jsondoc (#22925)

Fixes the assertion defect that happens when using `jsondoc --stdout`
(There is no outfile since its just stdout)

```
Error: unhandled exception: options.nim(732, 3) `not conf.outFile.isEmpty`  [AssertionDefect]
```

Also makes the output easier to parse by ending each module output with
a new line.
This commit is contained in:
Jake Leahy
2023-11-09 17:33:57 +11:00
committed by GitHub
parent e081f565cb
commit 60597adb10
2 changed files with 3 additions and 1 deletions

View File

@@ -1806,7 +1806,7 @@ proc writeOutputJson*(d: PDoc, useWarning = false) =
"moduleDescription": modDesc,
"entries": d.jEntriesFinal}
if optStdout in d.conf.globalOptions:
write(stdout, $content)
writeLine(stdout, $content)
else:
let dir = d.destFile.splitFile.dir
createDir(dir)

View File

@@ -725,6 +725,8 @@ proc genSuccessX*(conf: ConfigRef) =
elif conf.outFile.isEmpty and conf.cmd notin {cmdJsonscript} + cmdDocLike + cmdBackends:
# for some cmd we expect a valid absOutFile
output = "unknownOutput"
elif optStdout in conf.globalOptions:
output = "stdout"
else:
output = $conf.absOutFile
if conf.filenameOption != foAbs: output = output.AbsoluteFile.extractFilename