Add a local YAML config file for persistent settings

Reads $XDG_CONFIG_HOME/slocker-lite/config.yaml (falling back to
$HOME/.config/slocker-lite/config.yaml), organized into sections. Only
the "global" section's log-level is supported for now -- other options
are one-shot flags, not standing preferences. An explicit --log-level
on the command line always overrides the config file, the same way
SPDLOG_LEVEL already does.

Uses libyaml directly (yaml_dep was already declared in meson.build but
unused). A missing config file isn't an error; unknown sections/keys
are ignored for forward-compatibility; malformed YAML syntax is a hard
error.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gv3s5jckJKzh6JkMoi2Akz
This commit is contained in:
2026-08-21 12:31:40 +00:00
parent f7e7faed19
commit be5a0b8202
6 changed files with 173 additions and 1 deletions
+12
View File
@@ -95,6 +95,18 @@ Source layout (all under `src/`):
kill `slocker-lite` itself — without this, Ctrl-C (or `kill`) during `-r`'s `bwrap`
run would skip `run_container()`'s unmount/cleanup entirely, leaving the layer
imported and/or mounted.
- `config_file.{h,cpp}``load_config_file()` reads and parses (via libyaml's
document API, `<yaml.h>`) the `global` section of the local YAML config file
located by `config_file_path()` (`$XDG_CONFIG_HOME/slocker-lite/config.yaml`,
falling back to `$HOME/.config/slocker-lite/config.yaml`). Only `global.log-level`
is supported today — other long options are one-shot flags, not settings, so they
don't belong in a persistent config file. A missing file returns a
default-constructed (empty) `AppConfig`, not an error; unknown sections/keys are
ignored for forward-compatibility; malformed YAML syntax is a hard error. `main()`
applies `config->log_level` (via the existing `apply_log_level()`) right after
`spdlog::cfg::load_env_levels()` and before parsing CLI options, so an explicit
`--log-level` on the command line always overwrites it afterward — same precedence
pattern already used for `SPDLOG_LEVEL`.
Errors are logged via `spdlog::error`; every external command is also traced at debug
level in `run_process()`/`run_process_foreground()` (`src/process.cpp`) — visible via