ba0f3 / sim.nim

Parse config by defining an object

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Overload `loadObject(cfg: Config)`

enthus1ast opened this issue · comments

in my current config i use keys as an enumeration.

[csvtables]
# List all the tables you want to download as csv here.
# This section is ignored when you disable downloadCSV
Table1
Table2

for cases (and other corner cases) like this it might be beneficial,
to overload loadObject to accept an already parsed config.
So in my project i added:

proc loadObject*[T](cfg: Config, useSnakeCase = true): T =
  var sim = Sim(
    useSnakeCase: useSnakeCase,
    cfg: cfg,
    sections: initTable[string, Section]()
  )
  sim.mapSection()
  sim.getObj(result)

In addition, do you have an idea how such enumeration keys could be mapped to objects?

I know, you currently do such enumerations with a string separated by comma but i
found it easier (to comment out) and less syntax for my users to just enlist those keys.

Btw. your lib made my code much cleaner already :)

that's a great idea, I will try to implement it. In the meanwhile, you can solve it by using parseHook (see tests/test11.nim)