Using CLI arguments through modules and configuration files

The last time I built a complex system with a bunch of components (a blockchain) I used JSON files with ppx_yojson marshalling, for all configuration. There’s the problem of “distributing” the config objects to the various subsystems, and I don’t want to minimize that, but at least, having the wireline representation be automatically derived from the types was … very valuable. It allowed me to think solely in terms of the “configuration datatype”.

Right now I’m writing rather complex PPX rewriters (an attribute grammar evaluator-generator) and again, I’ve got a “demarshaller” from OCaml ASTs to a defined datatype, generated by a PPX rewriter, so that again, I don’t think in terms of the “wireline” OCaml AST, but rather the datatype that my PPX rewriter wants to consume.

Also: you know about ppx_cmdliner, yes? The last time I used cmdliner, I used that tool, and heartily recommend it. And also, of course, I heartily, heartily recommend cmdliner, but you already know that.

Last: logging is a special case, @CraigFe is correct, I think, in suggesting that you should use a logging library that has all the config-information for all its client modules. So: that logging library would have a way to configure which client modules should be logging verbosely, and the client modules themselves would ask the logging library “what’s my logging-level? INFO? ERROR? TRACE?” or the equivalent.

1 Like