Debian Codegraph @

guide/src/format/configuration/environment-variables.md

raw
1 # Environment variables
2
3 All configuration values can be overridden from the command line by setting the
4 corresponding environment variable. Because many operating systems restrict
5 environment variables to be alphanumeric characters or `_`, the configuration
6 key needs to be formatted slightly differently to the normal `foo.bar.baz` form.
7
8 Variables starting with `MDBOOK_` are used for configuration. The key is created
9 by removing the `MDBOOK_` prefix and turning the resulting string into
10 `kebab-case`. Double underscores (`__`) separate nested keys, while a single
11 underscore (`_`) is replaced with a dash (`-`).
12
13 For example:
14
15 - `MDBOOK_book` -> `book`
16 - `MDBOOK_BOOK` -> `book`
17 - `MDBOOK_BOOK__TITLE` -> `book.title`
18 - `MDBOOK_BOOK__TEXT_DIRECTION` -> `book.text-direction`
19
20 So by setting the `MDBOOK_BOOK__TITLE` environment variable you can override the
21 book's title without needing to touch your `book.toml`.
22
23 > **Note:** To facilitate setting more complex config items, the value of an
24 > environment variable is first parsed as JSON, falling back to a string if the
25 > parse fails.
26 >
27 > This means, if you so desired, you could override all book metadata when
28 > building the book with something like
29 >
30 > ```shell
31 > $ export MDBOOK_BOOK='{"title": "My Awesome Book", "authors": ["Michael-F-Bryan"]}'
32 > $ mdbook build
33 > ```
34
35 The latter case may be useful in situations where `mdbook` is invoked from a
36 script or CI, where it sometimes isn't possible to update the `book.toml` before
37 building.