[[include]]
[[include]] reads other configuration files into the file that contains it.
path names one file. dir names a directory, and Novis reads every *.toml file directly inside it, in the order of the file names. Files in subdirectories are not read. Both keys are relative to the directory of the file that contains the block. optional = true allows the file to be missing.
Novis reads all the files as one list of settings, and a later setting replaces an earlier one. An included file can therefore change a value from the file that included it. nvs config dump --origin shows which file set each value and which value it replaced.
Good to know: a missing file without optional = true is the error E0605. Two files that include each other are the error E0606. Blocks with double brackets, such as [[app]] and [[schedule]], are collected from all the files. A plain value is replaced.
Examples
The examples below run with this configuration file.
# The main file sets a memory limit, then reads every file in `conf.d`.# A setting in an included file replaces the same setting written here.[limits]memory = "128M"
[[include]]dir = "conf.d"
# This file does not exist. `optional = true` makes that allowed.[[include]]path = "local.toml"optional = trueSettings from several files
<?nvs// Shows one configuration that is split over several files.// `nvs.toml` sets the memory limit to `128M` and includes the files in `conf.d`.
// `conf.d` has two files. They are read in filename order, and the last value wins.// So this prints `512M`.echo Core\Config::get('memory'), "\n";512Minclude
Reads more settings from another file, or from every .toml file in a folder.
Use it to keep the settings of one machine apart from the settings you share. For example, the shared nvs.toml is in version control, and each server adds its database address in its own file. A folder is read in filename order, so a server can add a file without changing a shared one.
Novis reads a file's own settings first, and then the files it includes. When two files set the same setting, the file read later wins. So an included file changes the settings of the file that includes it, even if the [[include]] line is at the top. nvs config dump --origin shows which file set each value.
Good to know: optional = true allows a missing file. A file that cannot be read or parsed stops the server. So does a file that an account other than the server's could change.
Only nvs.toml sets this key. A request may not change it.
A change in the file takes effect a few seconds after you save it. The server does not restart.
The examples below run with this configuration file.
# Every request starts with 256M of memory.[limits]memory = "256M"One configuration split across files
<?nvs// `[[include]]` splits one configuration into more than one file. Each entry// names a file or a directory of files, and the server reads them in place.// This configuration has no include, so this program shows what a program// sees when the configuration is one file.
echo 'included files: ', Core\Config::get('include') ?? '(none — this checkout is one file)', "\n";
// `Core\Config::get('include')` returns `null`. A program sees only the final// value of each key. When two files set the same key, the later file wins.echo 'memory per request: ', Core\Config::get('limits.memory') ?? '(nothing)', "\n";
// A program cannot add an include. Only the person who runs the server may// choose which files it reads, so each `Core\Config::set` call below returns `false`.string $include = 'include';string $dir = 'include.dir';string $optional = 'include.optional';echo 'pull one in: ', Core\Config::set($include, 'conf.d/mine.toml') ? 'yes' : 'no', "\n";echo 'or a directory: ', Core\Config::set($dir, '/tmp/conf.d') ? 'yes' : 'no', "\n";echo 'or an optional: ', Core\Config::set($optional, 'true') ? 'yes' : 'no', "\n";
// An entry with `optional = true` may name a file that does not exist. If the file// exists but cannot be read or parsed, the server does not start.included files: (none — this checkout is one file)memory per request: 256Mpull one in: noor a directory: noor an optional: noChangelog
| Version | Change |
|---|---|
0.0.6 | The page of each setting says whether a request may change it with Core\Config::set. A page for a block lists the settings in it that a request may change. |
