This commit is contained in:
Daylin Morgan 2024-09-05 11:14:24 -05:00
parent a5668d426d
commit cd105ae69a
Signed by: daylin
GPG key ID: 950D13E9719334AD
2 changed files with 30 additions and 26 deletions

View file

@ -16,42 +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( let p = startProcess(
args[0], args[0],
args = args[1..^1], args = args[1..^1],
options = {poUsePath} options = {poUsePath}
) )
let outstrm = outputStream p let
let errstrm = errorStream p outstrm = peekableOutputStream p
# result.exitCode = -1 errstrm = peekableErrorStream p
# var line: string result.exitCode = -1
var line: string
# var cnt: int # var cnt: int
# while true: while true:
# echo cnt if CaptStdout in capture:
# if outstrm.readLine(line): if outstrm.readLine(line):
# result.stdout.add line & '\n' result.stdout.add line & '\n'
# if errstrm.readLine(line): if CaptStderr in capture:
# result.stderr.add line & '\n' if errstrm.readLine(line):
# result.exitCode = peekExitCode(p) result.stderr.add line & '\n'
# if result.exitCode != -1: break result.exitCode = peekExitCode(p)
# inc cnt if result.exitCode != -1: break
echo "process should have started?"
echo p.running, "<--running?" # result.exitCode = waitForExit p
close p
result = (
readAll outstrm,
readAll errstrm,
-1,
)
# result.exitCode = waitForExit p # result.exitCode = waitForExit p
# close 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

@ -111,7 +111,7 @@ proc toBuildNixosConfiguration(): seq[string] =
cmd.addArg "--dry-run" cmd.addArg "--dry-run"
cmd.addArgs nixosConfigAttrs() cmd.addArgs nixosConfigAttrs()
# let (_, err) = runCmdCaptWithSpinner(cmd, "running dry run build for: " & getHosts().join(" ")) # let (_, err) = runCmdCaptWithSpinner(cmd, "running dry run build for: " & getHosts().join(" "))
let (_, err, _) = runCmdCapt(cmd) let (_, err, _) = runCmdCapt(cmd, {CaptStderr})
let output = parseDryRunOutput err let output = parseDryRunOutput err
return output.toBuild.mapIt(it.storePath) return output.toBuild.mapIt(it.storePath)