Compare commits

..

No commits in common. "cd105ae69a7470af3ee5406e3573541963c58be3" and "add7992106cacc12a6dbdd96bb5c8390e0a903a6" have entirely different histories.

2 changed files with 20 additions and 33 deletions

View file

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

View file

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