Add functions for a simple CLI<->HTTP layer.
This commit is contained in:
parent
d368e85e33
commit
75541180cc
17
cliutils.nim
17
cliutils.nim
@ -93,7 +93,7 @@ proc execWithOutput*(command: string, workingDir:string = "",
|
|||||||
args: openArray[string] = [], env: StringTableRef = nil,
|
args: openArray[string] = [], env: StringTableRef = nil,
|
||||||
options: set[ProcessOption] = {poUsePath},
|
options: set[ProcessOption] = {poUsePath},
|
||||||
msgCB: HandleProcMsgCB = nil):
|
msgCB: HandleProcMsgCB = nil):
|
||||||
tuple[output: TaintedString, error: TaintedString, exitCode: int] =
|
tuple[output, error: TaintedString, exitCode: int] =
|
||||||
|
|
||||||
result = (TaintedString"", TaintedString"", -1)
|
result = (TaintedString"", TaintedString"", -1)
|
||||||
var outSeq, errSeq: seq[TaintedString]
|
var outSeq, errSeq: seq[TaintedString]
|
||||||
@ -183,3 +183,18 @@ proc termColor*(color: TermColor, bright, bold = false): string =
|
|||||||
|
|
||||||
proc withColor*(str: string, color: TermColor, bright, bold = false): string =
|
proc withColor*(str: string, color: TermColor, bright, bold = false): string =
|
||||||
return termColor(color, bright, bold) & str
|
return termColor(color, bright, bold) & str
|
||||||
|
|
||||||
|
let STRIP_ANSI_REGEX = re"\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]"
|
||||||
|
|
||||||
|
proc stripAnsi*(str: string): string = return str.replace(STRIP_ANSI_REGEX, "")
|
||||||
|
|
||||||
|
proc queryParamsToCliArgs*(queryParams: StringTableRef): seq[string] =
|
||||||
|
result = @[]
|
||||||
|
|
||||||
|
for k,v in queryParams:
|
||||||
|
# support ?arg1=val1&arg2=val2 -> cmd val1 val2
|
||||||
|
if k.startsWith("arg"): result.add(v)
|
||||||
|
|
||||||
|
else :
|
||||||
|
result[1].add("--" & k)
|
||||||
|
if v != "true": result[1].add(v) # support things like ?verbose=true -> cmd --verbose
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Package
|
# Package
|
||||||
|
|
||||||
version = "0.4.1"
|
version = "0.5.0"
|
||||||
author = "Jonathan Bernard"
|
author = "Jonathan Bernard"
|
||||||
description = "Helper functions for writing command line interfaces."
|
description = "Helper functions for writing command line interfaces."
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user