ConfigGenerator icon indicating copy to clipboard operation
ConfigGenerator copied to clipboard

Support for optional values

Open lucianomarisi opened this issue 7 years ago • 2 comments

Does configen support optional values? for example can we declare String? in the mapping file. The reasoning for this is that some environments don't need all the properties.

lucianomarisi avatar Mar 24 '17 11:03 lucianomarisi

Well, no, it's not supposed to. It specifically defeats the purpose of the tool, which is robustness.

But I think there is a way to beat the system if you really want to. Configen supports any type, which is how it allows enums such as, for example, LogLevel for which the value may be defined in the property list as .warning, .error, etc. This means you could define your type as String? and enter the value in the mapping file as nil or "some value" (note you need to provide the quotes in this case, because the value gets printed as is to the .swift source file.

I haven't tried this, and I wouldn't recommend it. You're better off defining the type as String and providing a value even where you don't need it. For example, in the case of a string, provide an empty string and in code only use it if non-empty. At least then it sticks out as missing in the environments that do rely on it.

samdods avatar Mar 28 '17 18:03 samdods