gleamunison/config

Live configuration: CLI overrides beat TOML, and TOML beats environment.

The previous config module was dead code because no TOML parser existed. This one owns one precedence rule for every process setting, using tom for an optional file and env for the process fallback. A missing file is normal; a malformed file or wrong value type is an operator error and is surfaced rather than silently ignored.

Types

pub type Config {
  Config(
    cli: dict.Dict(String, Value),
    toml: dict.Dict(String, tom.Toml),
  )
}

Constructors

pub type Value {
  StringVal(String)
  IntVal(Int)
  BoolVal(Bool)
}

Constructors

  • StringVal(String)
  • IntVal(Int)
  • BoolVal(Bool)

Values

pub fn empty() -> Config
pub fn flag(config: Config, key: String) -> Result(Bool, String)
pub fn int_or(
  config: Config,
  key: String,
  default: Int,
) -> Result(Int, String)
pub fn load() -> Result(Config, String)
pub fn load_from(file_path: String) -> Result(Config, String)
pub fn optional_string(
  config: Config,
  key: String,
) -> Result(option.Option(String), String)
pub fn path() -> String

The config file selected by GLEAMUNISON_CONFIG, else the project default.

pub fn resolve_profile() -> Result(String, String)

The one profile resolver for every admission gate: CLI overrides, then TOML, then the environment, then “local”. An empty string anywhere means unset. The Erlang bind and sandbox gates call this compiled function instead of reading the environment themselves, so a TOML-set profile is visible at admission time. Resolved per call — never cached at boot — and a malformed config file surfaces as an error the gate must refuse on.

pub fn string_or(
  config: Config,
  key: String,
  default: String,
) -> Result(String, String)
pub fn with_cli(
  config: Config,
  overrides: dict.Dict(String, Value),
) -> Config
✨ Search Document