mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-05-12 05:19:33 +00:00
* Soft-deprecate --cluster-id=N triggering the associated preset selection * Rewrite applyNetworkConf to apply user-set fields over preset fields * Add createNode(preset, mode, overrides, additions) nim api * Generate WakuNodeConfOverlay (all Option fields) from WakuNodeConf * New parser for configJson handles new messaging shape and full conf shape * Change all confbuilder defaults from literal values to DefaultXXX consts * Change int/bool WakuNodeConf fields to Option to get user intent w/o sentinels * Make Option CLI default-value help mention defaults now owned by confbuilder * Misc refactors, fixes * Add tests
38 lines
1.4 KiB
Nim
38 lines
1.4 KiB
Nim
{.push raises: [].}
|
|
|
|
import std/options
|
|
import results
|
|
import ./cli_args
|
|
import ./optionalize
|
|
|
|
const WakuNodeConfOverlayExcludes* = ["cmd", "execute", "mode", "preset"]
|
|
|
|
# Generates the WakuNodeConfOverlay type from the WakuNodeConf type.
|
|
# The generated type converts fields from type T to Option[T] if T != Option.
|
|
# Skips fields that are in WakuNodeConfOverlayExcludes.
|
|
optionalizeType(WakuNodeConfOverlay, WakuNodeConf, WakuNodeConfOverlayExcludes)
|
|
|
|
proc init*(T: type WakuNodeConfOverlay): WakuNodeConfOverlay =
|
|
## Default config overlay where every field is `none`.
|
|
return WakuNodeConfOverlay()
|
|
|
|
proc applyAsOverride*(conf: var WakuNodeConf, overlay: WakuNodeConfOverlay) =
|
|
## For all fields, overlay.some() overrides field of same name in conf.
|
|
for confName, confValue in fieldPairs(conf):
|
|
for ovName, ovValue in fieldPairs(overlay):
|
|
when confName == ovName:
|
|
if ovValue.isSome():
|
|
when typeof(confValue) is Option:
|
|
confValue = ovValue
|
|
else:
|
|
confValue = ovValue.get()
|
|
|
|
proc applyAsAddition*(conf: var WakuNodeConf, overlay: WakuNodeConfOverlay) =
|
|
## For all seq fields, overlay.some() concats to field of same name in conf.
|
|
for confName, confValue in fieldPairs(conf):
|
|
for ovName, ovValue in fieldPairs(overlay):
|
|
when confName == ovName:
|
|
when typeof(confValue) is seq:
|
|
if ovValue.isSome() and ovValue.get().len > 0:
|
|
confValue = confValue & ovValue.get()
|