Compare commits

..

7 commits

Author SHA1 Message Date
cd105ae69a
debug 2024-09-05 12:39:41 -05:00
a5668d426d
just close it earlier 2024-09-05 11:10:41 -05:00
c55dd04671
why is it hanging 2024-09-05 11:05:17 -05:00
b83c345693
og impl 2024-09-05 11:01:04 -05:00
46912c29af
be noisy 2024-09-05 10:08:09 -05:00
2614aeb181
try closing it? 2024-09-05 09:57:21 -05:00
af89a69eff
add test run 2024-09-05 09:36:20 -05:00
2 changed files with 33 additions and 20 deletions

View file

@ -16,32 +16,46 @@ proc runCmd*(cmd: string): int =
debug fmt"running cmd: {cmd}" debug fmt"running cmd: {cmd}"
execCmd cmd execCmd cmd
proc runCmdCapt*(cmd: string): tuple[stdout, stderr: string, exitCode: int] = type
CaptureGrp* = enum
CaptStdout
CaptStderr
proc runCmdCapt*(
cmd: string,
capture: set[CaptureGrp],
): tuple[stdout, stderr: string, exitCode: int] =
debug fmt"running cmd: {cmd}"
let args = cmd.splitWhitespace() let args = cmd.splitWhitespace()
let p = startProcess(args[0], args = args[1..^1], options = {poUsePath}) let p = startProcess(
let ostrm = outputStream p args[0],
let errstrm = errorStream p args = args[1..^1],
options = {poUsePath}
)
let
outstrm = peekableOutputStream p
errstrm = peekableErrorStream p
result.exitCode = -1 result.exitCode = -1
var line = newStringOfCap(120) var line: string
# var cnt: int
while true: while true:
if ostrm.readLine(line): if CaptStdout in capture:
result.stdout.add line & '\n' if outstrm.readLine(line):
if errstrm.readLine(line): result.stdout.add line & '\n'
result.stderr.add line & '\n' if CaptStderr in capture:
if errstrm.readLine(line):
result.stderr.add line & '\n'
result.exitCode = peekExitCode(p) result.exitCode = peekExitCode(p)
if result.exitCode != -1: break if result.exitCode != -1: break
# result = ( # result.exitCode = waitForExit p
# readAll p.outputStream, # result.exitCode = waitForExit p
# readAll p.errorStream, # close p
# waitForExit p
# )
close p close p
proc runCmdCaptWithSpinner*(cmd: string, msg: string = ""): tuple[output, err: string] = proc runCmdCaptWithSpinner*(cmd: string, msg: string = "", capture: set[CaptureGrp] = {CaptStdout}): tuple[output, err: string] =
debug fmt"running command: {cmd}"
withSpinner(msg): withSpinner(msg):
let (output, err, code) = runCmdCapt(cmd) let (output, err, code) = runCmdCapt(cmd, capture)
if code != 0: if code != 0:
stderr.writeLine("stdout\n" & output) stderr.writeLine("stdout\n" & output)
stderr.writeLine("stderr\n" & err) stderr.writeLine("stderr\n" & err)

View file

@ -110,9 +110,8 @@ proc toBuildNixosConfiguration(): seq[string] =
var cmd = nixCommand("build") var cmd = nixCommand("build")
cmd.addArg "--dry-run" cmd.addArg "--dry-run"
cmd.addArgs nixosConfigAttrs() cmd.addArgs nixosConfigAttrs()
debug "trying with ouptut" # let (_, err) = runCmdCaptWithSpinner(cmd, "running dry run build for: " & getHosts().join(" "))
discard execCmd(cmd) let (_, err, _) = runCmdCapt(cmd, {CaptStderr})
let (_, err) = runCmdCaptWithSpinner(cmd, "running dry run build for: " & getHosts().join(" "))
let output = parseDryRunOutput err let output = parseDryRunOutput err
return output.toBuild.mapIt(it.storePath) return output.toBuild.mapIt(it.storePath)