Add CombinedConfig.getVal that raises an exception if the config key is not found.
This commit is contained in:
parent
b9a69809eb
commit
8036af6bc8
@ -10,7 +10,7 @@ type
|
|||||||
|
|
||||||
TermColor = ForegroundColor or BackgroundColor
|
TermColor = ForegroundColor or BackgroundColor
|
||||||
|
|
||||||
proc getVal*(cfg: CombinedConfig, key, default: string): string =
|
proc getVal*(cfg: CombinedConfig, key: string): string =
|
||||||
let argKey = "--" & key
|
let argKey = "--" & key
|
||||||
let envKey = key.replace('-', '_').toUpper
|
let envKey = key.replace('-', '_').toUpper
|
||||||
let jsonKey = key.replace(re"(-\w)", proc (m: RegexMatch): string = ($m)[1..1].toUpper)
|
let jsonKey = key.replace(re"(-\w)", proc (m: RegexMatch): string = ($m)[1..1].toUpper)
|
||||||
@ -27,8 +27,11 @@ proc getVal*(cfg: CombinedConfig, key, default: string): string =
|
|||||||
of JNull: return ""
|
of JNull: return ""
|
||||||
of JObject: return $node
|
of JObject: return $node
|
||||||
of JArray: return $node
|
of JArray: return $node
|
||||||
else: return default
|
else: raise newException(ValueError, "cannot find a configuration value for \"" & key & "\"")
|
||||||
|
|
||||||
|
proc getVal*(cfg: CombinedConfig, key, default: string): string =
|
||||||
|
try: return getVal(cfg, key)
|
||||||
|
except: return default
|
||||||
|
|
||||||
proc loadEnv*(): StringTableRef =
|
proc loadEnv*(): StringTableRef =
|
||||||
result = newStringTable()
|
result = newStringTable()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user