How to manage global configuration


#1

I’m new to Rust. So bear with me…

I’m looking to have a “Global Configuration” construct that I can access from any place in the application I’m coding. Now, this could be achieve with a simple struct but I have a few requirements.

  1. It is a commandline application. I’m using Clap. I’d like that the commandline arguments take superiority over the default configuration.

  2. I’d like to read the environment variables and apply them as well. They do not take superiority over the arguments passed to the CLI.

  3. Default configuration. That configuration is determined at execution time (it’s not static).

How I think this will happen:

  1. Rust initialize the default configuration (some kind of a struct I think).
  2. Rust loads up the environment variables and replaces the default configuration where it applies.
  3. Rust does that too for the arguments passed to the CLI.

Anybody did something similar?