diff --git a/cliutils.nimble b/cliutils.nimble index 992e056..d0b91b3 100644 --- a/cliutils.nimble +++ b/cliutils.nimble @@ -1,10 +1,10 @@ # Package -version = "0.6.5" +version = "0.7.0" author = "Jonathan Bernard" description = "Helper functions for writing command line interfaces." license = "MIT" # Dependencies -requires @["nim >= 0.19.0", "docopt >= 0.6.8"] +requires @["nim >= 1.6.0", "docopt >= 0.6.8"] diff --git a/cliutilspkg/procutil.nim b/cliutilspkg/procutil.nim index 12664b0..e269088 100644 --- a/cliutilspkg/procutil.nim +++ b/cliutilspkg/procutil.nim @@ -1,21 +1,20 @@ -import osproc, sequtils, streams, strtabs +import osproc, streams, strtabs, strutils ## Process execution -type HandleProcMsgCB* = proc (outMsg: TaintedString, - errMsg: TaintedString, cmd: string): void +type HandleProcMsgCB* = proc (outMsg: string, errMsg: string, cmd: string): void -proc sendMsg*(h: HandleProcMsgCB, outMsg: TaintedString, - errMsg: TaintedString = "", cmd: string = ""): void = +proc sendMsg*(h: HandleProcMsgCB, outMsg: string, + errMsg: string = "", cmd: string = ""): void = if h != nil: h(outMsg, errMsg, cmd) proc makeProcMsgHandler*(outSink, errSink: File, prefixCmd: bool = true): HandleProcMsgCB = - result = proc(outMsg, errMsg: TaintedString, cmd: string): void {.closure.} = + result = proc(outMsg, errMsg: string, cmd: string): void {.closure.} = let prefix = if cmd.len == 0 or not prefixCmd: "" else: cmd & ": " if outMsg.len > 0: outSink.writeLine(prefix & outMsg) if errMsg.len > 0: errSink.writeLine(prefix & errMsg) proc makeProcMsgHandler*(outSink, errSink: Stream, prefixCmd: bool = true): HandleProcMsgCB = - result = proc(outMsg, errMsg: TaintedString, cmd: string): void {.closure.} = + result = proc(outMsg, errMsg: string, cmd: string): void {.closure.} = let prefix = if cmd.len == 0 or not prefixCmd: "" else: cmd & ": " if outMsg.len > 0: outSink.writeLine(prefix & outMsg) if errMsg.len > 0: errSink.writeLine(prefix & errMsg) @@ -24,7 +23,7 @@ proc combineProcMsgHandlers*(a, b: HandleProcMsgCB): HandleProcMsgCB = if a == nil: result = b elif b == nil: result = a else: - result = proc(cmd: string, outMsg, errMsg: TaintedString): void = + result = proc(cmd: string, outMsg, errMsg: string): void = a(cmd, outMsg, errMsg) b(cmd, outMsg, errMsg) @@ -33,7 +32,7 @@ proc waitFor*(p: Process, msgCB: HandleProcMsgCB, procCmd: string = ""): int = var pout = outputStream(p) var perr = errorStream(p) - var line = newStringOfCap(120).TaintedString + var line = newStringOfCap(120) while true: if pout.readLine(line): msgCB.sendMsg(line, "", procCmd) @@ -57,13 +56,13 @@ proc execWithOutput*(command: string, workingDir:string = "", args: openArray[string] = [], env: StringTableRef = nil, options: set[ProcessOption] = {poUsePath}, msgCB: HandleProcMsgCB = nil): - tuple[output, error: TaintedString, exitCode: int] = + tuple[output, error: string, exitCode: int] = - result = (TaintedString"", TaintedString"", -1) - var outSeq, errSeq: seq[TaintedString] + result = ("", "", -1) + var outSeq, errSeq: seq[string] outSeq = @[]; errSeq = @[] let outputCollector = combineProcMsgHandlers(msgCB, - proc(outMsg, errMsg: TaintedString, cmd: string): void {.closure.} = + proc(outMsg, errMsg: string, cmd: string): void {.closure.} = if outMsg.len > 0: outSeq.add(outMsg) if errMsg.len > 0: errSeq.add(errMsg))