ITADN

Feature suggestion: render an example JSON/YAML file with all settings that have defaults

#18Openfpringle 创建于 2025-05-02
F
fpringlecommented
Hi, I've just discovered this library after a few days of wrestling with other config parsing solutions in the ecosystem, and I have to say this blows them all out of the water. Bravo. I had one idea: in a similar way that `OptEnvConf.Nix` lets us render a Nix file with module options for each leaf of the `Parser` tree that has a `ConfigValSettings`; would it be possible to do something similiar to generate an example JSON/YAML file that can be used as a starting point to write config files, that are "guaranteed" to be compatible for the `Parser`? You could even add the non-default settings with placeholders. For example: ```haskell data DBConf = DBConf { host :: String , port :: Int , password :: String } instance HasParser DBConf where settingsParser = subConfig "db" $ DBConf <$> setting [conf "host", value "localhost"] <*> setting [conf "port", value 8080] <*> setting [conf "password"] renderSettingsYaml :: HasParser a => Text renderSettingsYaml = ... ``` Then, `renderSettingsYaml @DBConf` would produce: ```yaml db: host: localhost port: 8080 password: "String placeholder" ``` This would be increidbly useful to bundle with an application, to hand to the end users as a starting point for their config files. Anyway, thanks again!
1 条评论