Compare commits
5 Commits
eaffb20df5
...
0.10.2
| Author | SHA1 | Date | |
|---|---|---|---|
| c0e96f99a8 | |||
| c1dbcd90a4 | |||
| a33500f6d4 | |||
| ca7b2a620a | |||
| f2c729fd7d |
14
cliutils.nim
14
cliutils.nim
@@ -21,14 +21,20 @@ proc termColor*(color: TermColor, bright, bold = false): string =
|
||||
if bright: inc(colorVal, 60)
|
||||
return "\e[" & $colorVal & (if bold: ";1" else: "") & "m"
|
||||
|
||||
proc withColor*(str: string, color: TermColor, bright, bold = false): string =
|
||||
return termColor(color, bright, bold) & str
|
||||
|
||||
proc termFmt*(str: string, color: TermColor, bright, bold, underline, skipReset = false): string =
|
||||
result = termColor(color, bright, bold) & str
|
||||
if underline: result = "\e[4m" & result
|
||||
if not skipReset: result &= termReset
|
||||
|
||||
proc withColor*(str: string, color: TermColor, bright, bold, skipReset = false): string =
|
||||
termFmt(str, color, bright, bold, false, skipReset)
|
||||
|
||||
proc stripAnsi*(str: string): string =
|
||||
let STRIP_ANSI_REGEX = re"\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]"
|
||||
let STRIP_ANSI_REGEX = re"\x1B\[([0-9]{1,2}(;[0-9]{0,2})?)?[m|K]"
|
||||
return str.replace(STRIP_ANSI_REGEX, "")
|
||||
|
||||
|
||||
proc doParseQueryParams[T](queryParams: T): seq[string] =
|
||||
result = @[]
|
||||
|
||||
@@ -40,8 +46,10 @@ proc doParseQueryParams[T](queryParams: T): seq[string] =
|
||||
result.add("--" & k)
|
||||
if v != "true": result.add(v) # support things like ?verbose=true -> cmd --verbose
|
||||
|
||||
|
||||
proc queryParamsToCliArgs*(queryParams: Table[string, string]): seq[string] =
|
||||
doParseQueryParams(queryParams)
|
||||
|
||||
|
||||
proc queryParamsToCliArgs*(queryParams: StringTableRef): seq[string] =
|
||||
doParseQueryParams(queryParams)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Package
|
||||
|
||||
version = "0.9.1"
|
||||
version = "0.10.2"
|
||||
author = "Jonathan Bernard"
|
||||
description = "Helper functions for writing command line interfaces."
|
||||
license = "MIT"
|
||||
|
||||
@@ -95,7 +95,7 @@ proc getJson*(
|
||||
elif cfg.json.hasKey(jsonKey): return cfg.json[jsonKey]
|
||||
else: raise newException(ValueError, "cannot find a configuration value for \"" & key & "\"")
|
||||
except Exception:
|
||||
raise newException(ValueError, "cannot parse value as JSON:" & getCurrentExceptionMsg())
|
||||
raise newException(ValueError, "cannot parse [" & getVal(cfg, key) & "] as JSON:" & getCurrentExceptionMsg())
|
||||
|
||||
proc getJson*(
|
||||
cfg: CombinedConfig,
|
||||
|
||||
Reference in New Issue
Block a user