Slight environment variable adjustment

When configuring iocaine via environment variables, sections and
settings were separated by two underlines, but the `IOCAINE_` prefix
only had one. This felt weird, so now iocaine supports an `IOCAINE__`
prefix too, and keeps recognizing the old one too.

Documentation and examples updated to use the new naming. No mention of
the backwards compatibility - I'll just silently support that.

Signed-off-by: Gergely Nagy <me@gergo.csillger.hu>
This commit is contained in:
Gergely Nagy 2025-01-25 02:16:06 +01:00
parent c0c3210af8
commit e3306e7998
No known key found for this signature in database
3 changed files with 7 additions and 6 deletions

View file

@ -11,6 +11,6 @@ services:
volumes:
- ./container-volume:/data
environment:
- IOCAINE_SERVER__BIND="0.0.0.0:42069"
- IOCAINE_SOURCES__WORDS="/data/wordlist.txt"
- IOCAINE_SOURCES__MARKOV=["/data/training-text.txt"]
- IOCAINE__SERVER__BIND="0.0.0.0:42069"
- IOCAINE__SOURCES__WORDS="/data/wordlist.txt"
- IOCAINE__SOURCES__MARKOV=["/data/training-text.txt"]

View file

@ -16,7 +16,7 @@ The `[server]` section is used to configure the address and port the server will
bind = "127.0.0.1:42069"
```
This parameter is available as `IOCAINE_SERVER__BIND` when configuring via environment variables.
This parameter is available as `IOCAINE__SERVER__BIND` when configuring via environment variables.
# `[sources]`
@ -32,7 +32,7 @@ The first option, `words`, refers to a word list file, with one word per line. W
The second option, `markov`, is a list of files used to train the markov chain generator. These will be used to generate the main content.
These parameters are available as `IOCAINE_SOURCES__WORDS` and `IOCAINE_SOURCES__MARKOV`, respectively, when configuring via environment variables. Do note that if configuring `iocaine` this way, the `IOCAINE_SOURCES__MARKOV` environment variable *must* be a TOML list: `IOCAINE_SOURCES__MARKOV='["/var/lib/iocaine/markov/bee-movie.txt"]'`.
These parameters are available as `IOCAINE__SOURCES__WORDS` and `IOCAINE__SOURCES__MARKOV`, respectively, when configuring via environment variables. Do note that if configuring `iocaine` this way, the `IOCAINE__SOURCES__MARKOV` environment variable *must* be a TOML list: `IOCAINE__SOURCES__MARKOV='["/var/lib/iocaine/markov/bee-movie.txt"]'`.
# `[generator]`
@ -56,4 +56,4 @@ backlink = true
initial_seed = ""
```
When configuring through environment variables, these settings are available via `IOCAINE_GENERATOR__MARKOV__PARAGRAPHS__MIN`, `IOCAINE_GENERATOR__MARKOV__PARAGRAPHS_MAX`, `IOCAINE_GENERATOR__MARKOV__WORDS__MIN`, `IOCAINE_GENERATOR__MARKOV__WORDS__MAX`, `IOCAINE_GENERATOR__LINKS__MIN`, `IOCAINE_GENERATOR__LINKS__MAX`, and `IOCAINE_GENERATOR__LINKS__BACKLINK`, `IOCAINE_GENERATOR__INITIAL_SEED` respectively.
When configuring through environment variables, these settings are available via `IOCAINE__GENERATOR__MARKOV__PARAGRAPHS__MIN`, `IOCAINE__GENERATOR__MARKOV__PARAGRAPHS_MAX`, `IOCAINE__GENERATOR__MARKOV__WORDS__MIN`, `IOCAINE__GENERATOR__MARKOV__WORDS__MAX`, `IOCAINE__GENERATOR__LINKS__MIN`, `IOCAINE__GENERATOR__LINKS__MAX`, and `IOCAINE__GENERATOR__LINKS__BACKLINK`, `IOCAINE__GENERATOR__INITIAL_SEED` respectively.

View file

@ -29,6 +29,7 @@ async fn main() -> Result<()> {
let config: Config = Figment::new()
.merge(FileAdapter::wrap(Env::prefixed("IOCAINE_").split("__")))
.merge(FileAdapter::wrap(Env::prefixed("IOCAINE__").split("__")))
.merge(FileAdapter::wrap(Toml::file(&args.config_file)))
.extract()
.unwrap_or_else(|err| {