@@ -979,29 +979,67 @@ macro configurationRtti(RecordType: type): untyped =
979979 result = newTree (nnkPar, newLitFixed cmdInfo, fieldSetters)
980980
981981when hasSerialization:
982- proc addConfigFile * (secondarySources: auto ,
983- Format: type ,
984- path: InputFile ) {.raises : [ConfigurationError ].} =
982+ template addConfigFileImpl (
983+ secondarySources: auto ,
984+ Format: type SerializationFormat ,
985+ path: InputFile ,
986+ params: varargs [untyped ]
987+ ): untyped =
985988 try :
986- secondarySources.data.add loadFile (Format , string path,
987- type (secondarySources.data[0 ]))
989+ secondarySources.data.add loadFile (
990+ Format , string path, typeof (secondarySources.data[0 ]), params
991+ )
988992 except SerializationError as err:
989993 raise newException (ConfigurationError , err.formatMsg (string path), err)
990994 except IOError as err:
991995 raise newException (ConfigurationError ,
992996 " Failed to read config file at '" & string (path) & " ': " & err.msg)
993997
994- proc addConfigFileContent * (secondarySources: auto ,
995- Format: type ,
996- content: string ) {.raises : [ConfigurationError ].} =
998+ template addConfigFileWithParams * (
999+ secondarySources: auto ,
1000+ Format: type SerializationFormat ,
1001+ path: InputFile ,
1002+ params: varargs [untyped ]
1003+ ): untyped =
1004+ addConfigFileImpl (secondarySources, Format , path, params)
1005+
1006+ proc addConfigFile * (
1007+ secondarySources: auto ,
1008+ Format: type SerializationFormat ,
1009+ path: InputFile
1010+ ) {.raises : [ConfigurationError ].} =
1011+ addConfigFileImpl (secondarySources, Format , path)
1012+
1013+ template addConfigFileContentImpl (
1014+ secondarySources: auto ,
1015+ Format: type SerializationFormat ,
1016+ content: string ,
1017+ params: varargs [untyped ]
1018+ ): untyped =
9971019 try :
998- secondarySources.data.add decode (Format , content,
999- type (secondarySources.data[0 ]))
1020+ secondarySources.data.add decode (
1021+ Format , content, type (secondarySources.data[0 ], params)
1022+ )
10001023 except SerializationError as err:
10011024 raise newException (ConfigurationError , err.formatMsg (" <content>" ), err)
10021025 except IOError :
10031026 raiseAssert " This should not be possible"
10041027
1028+ template addConfigFileContentWithParams * (
1029+ secondarySources: auto ,
1030+ Format: type SerializationFormat ,
1031+ content: string ,
1032+ params: varargs [untyped ]
1033+ ): untyped =
1034+ addConfigFileContentImpl (secondarySources, Format , content, params)
1035+
1036+ proc addConfigFileContent * (
1037+ secondarySources: auto ,
1038+ Format: type SerializationFormat ,
1039+ content: string
1040+ ) {.raises : [ConfigurationError ].} =
1041+ addConfigFileContentImpl (secondarySources, Format , content)
1042+
10051043func constructEnvKey * (prefix: string , key: string ): string {.raises : [].} =
10061044 # # Generates env. variable names from keys and prefix following the
10071045 # # IEEE Open Group env. variable spec: https://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap08.html
0 commit comments