mirror of
https://github.com/daylinmorgan/oizys.git
synced 2024-11-09 20:33:15 -06:00
Compare commits
No commits in common. "cd105ae69a7470af3ee5406e3573541963c58be3" and "add7992106cacc12a6dbdd96bb5c8390e0a903a6" have entirely different histories.
cd105ae69a
...
add7992106
2 changed files with 20 additions and 33 deletions
|
@ -16,46 +16,32 @@ proc runCmd*(cmd: string): int =
|
||||||
debug fmt"running cmd: {cmd}"
|
debug fmt"running cmd: {cmd}"
|
||||||
execCmd cmd
|
execCmd cmd
|
||||||
|
|
||||||
type
|
proc runCmdCapt*(cmd: string): tuple[stdout, stderr: string, exitCode: int] =
|
||||||
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 = args[1..^1], options = {poUsePath})
|
||||||
args[0],
|
let ostrm = outputStream p
|
||||||
args = args[1..^1],
|
let errstrm = errorStream p
|
||||||
options = {poUsePath}
|
|
||||||
)
|
|
||||||
let
|
|
||||||
outstrm = peekableOutputStream p
|
|
||||||
errstrm = peekableErrorStream p
|
|
||||||
result.exitCode = -1
|
result.exitCode = -1
|
||||||
var line: string
|
var line = newStringOfCap(120)
|
||||||
# var cnt: int
|
|
||||||
while true:
|
while true:
|
||||||
if CaptStdout in capture:
|
if ostrm.readLine(line):
|
||||||
if outstrm.readLine(line):
|
|
||||||
result.stdout.add line & '\n'
|
result.stdout.add line & '\n'
|
||||||
if CaptStderr in capture:
|
|
||||||
if errstrm.readLine(line):
|
if errstrm.readLine(line):
|
||||||
result.stderr.add line & '\n'
|
result.stderr.add line & '\n'
|
||||||
result.exitCode = peekExitCode(p)
|
result.exitCode = peekExitCode(p)
|
||||||
if result.exitCode != -1: break
|
if result.exitCode != -1: break
|
||||||
|
|
||||||
# result.exitCode = waitForExit p
|
# result = (
|
||||||
# result.exitCode = waitForExit p
|
# readAll p.outputStream,
|
||||||
# close p
|
# readAll p.errorStream,
|
||||||
|
# waitForExit p
|
||||||
|
# )
|
||||||
close 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):
|
withSpinner(msg):
|
||||||
let (output, err, code) = runCmdCapt(cmd, capture)
|
let (output, err, code) = runCmdCapt(cmd)
|
||||||
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)
|
||||||
|
|
|
@ -110,8 +110,9 @@ 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()
|
||||||
# let (_, err) = runCmdCaptWithSpinner(cmd, "running dry run build for: " & getHosts().join(" "))
|
debug "trying with ouptut"
|
||||||
let (_, err, _) = runCmdCapt(cmd, {CaptStderr})
|
discard execCmd(cmd)
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue