Skip to content

Implement the 'Partial Options Monoid' pattern for the configuration #130

Description

@chshersh

This pattern is common in the FP world. The description (in Haskell) can be found here:

The idea is the following:

  • Create the Options type with all configuration fields optional

  • Create functions to create this Options type from different environments:

    • Hardcoded default
    • Environment variables
    • Files
    • CLI options

    It's absolutely okay for different environments to fill only some parts of the config.

  • Implement a function to combine two Options with the second argument overriding the previous values if they both are present (otherwise, take the one that is not None)

  • Read options on start from all four sources and combine them in the following order of increasing priority (e.g. CLI arguments are more important than everything else)

    1. Defaults.
    2. Environment variables
    3. Configuration file.
    4. CLI flags

That's all! With this approach, it should be possible to configure different options from different sources and have a uniform config.

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLICommand Line InterfaceconfigTOML configuration, config-related CLI optionshacktoberfesthttps://hacktoberfest.com/refactoring

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions