Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
b1cc4fbe51 | |||
4e5152bed3 |
@ -1,9 +1,9 @@
|
|||||||
import nre, terminal, strtabs, tables, unicode
|
import nre, terminal, strtabs, tables, unicode
|
||||||
import strutils except toUpper, toLower
|
import strutils except toUpper, toLower
|
||||||
|
|
||||||
import ./cliutilspkg/config
|
import ./cliutils/config
|
||||||
import ./cliutilspkg/daemonize
|
import ./cliutils/daemonize
|
||||||
import ./cliutilspkg/procutil
|
import ./cliutils/procutil
|
||||||
|
|
||||||
export config
|
export config
|
||||||
export daemonize
|
export daemonize
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
# Package
|
# Package
|
||||||
|
|
||||||
version = "0.7.0"
|
version = "0.8.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"
|
||||||
|
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
|
|
||||||
requires @["nim >= 1.6.0", "docopt >= 0.6.8"]
|
requires @["nim >= 1.6.0", "docopt >= 0.6.8"]
|
||||||
|
@ -57,6 +57,20 @@ proc getVal*(cfg: CombinedConfig, key, default: string): string =
|
|||||||
try: return getVal(cfg, key)
|
try: return getVal(cfg, key)
|
||||||
except: return default
|
except: return default
|
||||||
|
|
||||||
|
proc getJson*(cfg: CombinedConfig, key: string): JsonNode =
|
||||||
|
let argKey = "--" & key
|
||||||
|
let envKey = key.replace('-', '_').toUpper
|
||||||
|
let jsonKey = key.replace(re"(-\w)", proc (m: RegexMatch): string = ($m)[1..1].toUpper)
|
||||||
|
|
||||||
|
if cfg.docopt.contains(argKey) and cfg.docopt[argKey]: return parseJson($cfg.docopt[argKey])
|
||||||
|
elif existsEnv(envKey): return parseJson(getEnv(envKey))
|
||||||
|
elif cfg.json.hasKey(jsonKey): return cfg.json[jsonKey]
|
||||||
|
else: raise newException(ValueError, "cannot find a configuration value for \"" & key & "\"")
|
||||||
|
|
||||||
|
proc getJson*(cfg: CombinedConfig, key: string, default: JsonNode): JsonNode =
|
||||||
|
try: return getJson(cfg, key)
|
||||||
|
except: return default
|
||||||
|
|
||||||
proc loadEnv*(): StringTableRef =
|
proc loadEnv*(): StringTableRef =
|
||||||
result = newStringTable()
|
result = newStringTable()
|
||||||
|
|
Reference in New Issue
Block a user