mirror of
https://github.com/status-im/nim-confutils.git
synced 2025-02-21 00:08:17 +00:00
fixes string encoding for envvar serialization
This commit is contained in:
parent
a263d76bc0
commit
f4087c1789
@ -36,16 +36,24 @@ proc readValue*[T](r: var EnvvarReader, value: var T)
|
||||
mixin readValue
|
||||
# TODO: reduce allocation
|
||||
|
||||
when T is (SomePrimitives or range or string):
|
||||
when T is string:
|
||||
let key = constructKey(r.prefix, r.key)
|
||||
value = os.getEnv(key)
|
||||
|
||||
elif T is (SomePrimitives or range):
|
||||
let key = constructKey(r.prefix, r.key)
|
||||
getValue(key, value)
|
||||
|
||||
elif T is Option:
|
||||
let key = constructKey(r.prefix, r.key)
|
||||
if existsEnv(key):
|
||||
var outVal: getUnderlyingType(value)
|
||||
getValue(key, outVal)
|
||||
value = some(outVal)
|
||||
type uType = getUnderlyingType(value)
|
||||
var outVal: uType
|
||||
when uType is string:
|
||||
value = some(os.getEnv(key))
|
||||
else:
|
||||
r.readValue(outVal)
|
||||
value = some(outVal)
|
||||
|
||||
elif T is (seq or array):
|
||||
when uTypeIsPrimitives(T):
|
||||
|
@ -1,7 +1,6 @@
|
||||
import
|
||||
typetraits, options, tables,
|
||||
serialization,
|
||||
./utils
|
||||
typetraits, options, tables, os,
|
||||
serialization, ./utils
|
||||
|
||||
type
|
||||
EnvvarWriter* = object
|
||||
@ -15,10 +14,14 @@ proc writeValue*(w: var EnvvarWriter, value: auto) =
|
||||
mixin enumInstanceSerializedFields, writeValue, writeFieldIMPL
|
||||
# TODO: reduce allocation
|
||||
|
||||
when value is (SomePrimitives or range or string):
|
||||
when value is string:
|
||||
let key = constructKey(w.prefix, w.key)
|
||||
os.putEnv(key, value)
|
||||
|
||||
elif value is (SomePrimitives or range):
|
||||
let key = constructKey(w.prefix, w.key)
|
||||
setValue(key, value)
|
||||
|
||||
|
||||
elif value is Option:
|
||||
if value.isSome:
|
||||
w.writeValue value.get
|
||||
|
Loading…
x
Reference in New Issue
Block a user