cli-engine-macros 0.2.0

Derive macro backing cli-engine's EnvConfig
Documentation

#[derive(EnvConfig)] — see cli_engine::env_config for the trait and runtime pieces this macro's generated code calls into.

Per-field #[env_config(...)] attributes:

  • key = "..." — TOML key to look up (default: the field's Rust name).
  • env = "SUFFIX" — opt-in environment-variable suffix.
  • default = <expr> — literal fallback of the field's own type.
  • default_fn = <path>fn(&SourceChain<'_>) -> T, computed lazily.
  • from_toml = <path>fn(&cli_engine::env_config::toml::Value) -> Result<T, String>, replaces the default T: DeserializeOwned conversion. Name the parameter type through cli_engine::env_config::toml (re-exported) rather than a direct toml dependency of your own, so your crate doesn't need to track cli-engine's toml version.
  • from_env = <path>fn(&str) -> Result<T, String>, replaces the default T: FromStr conversion.
  • to_toml = <path>fn(T) -> cli_engine::env_config::toml::Value, replaces the default T: Into<toml::Value> conversion used when building an EnvTable from an instance (see impl From<Self> for EnvTable, generated alongside EnvConfig so a compiled-in environment can be registered as a plain struct value via Environments::with_environment).
  • allow_blank — bare marker (no value); by default, a source that answers with an empty-or-whitespace-only string, or an empty TOML array, is treated as not having answered at all, so the field keeps looking at the rest of the SourceChain (and ultimately falls to default/default_fn) instead of accepting ""/[] literally. This default fits nearly every field: a blank or empty override is essentially always a mistake or an unset placeholder, never a real value. Set allow_blank on the rare field where an explicit "" or [] is itself a meaningful, literal answer distinct from "unset."

default and default_fn are mutually exclusive.