Add -w/--write-config to bootstrap a fully-populated config file

Writes every supported config option explicitly -- the six
unshare-* bools defaulted via value_or(true), log-level captured
from the actually active spdlog level (so an explicit --log-level
passed alongside -w is persisted too) -- creating the file and its
parent directory if missing, and prints its full path. Existing
values (including volumes) are preserved untouched.

Also fixes a stale README row left over from unplugging the
namespace probe out of -t/--test.
This commit is contained in:
2026-08-30 09:44:03 +00:00
parent bcae8bbcd4
commit ace71e0474
5 changed files with 81 additions and 6 deletions
+18 -2
View File
@@ -115,6 +115,22 @@ Source layout (all under `src/`):
already gone) — see `config_file.{h,cpp}` below for what a "volume" means here (a
distinct concept from `OciImageConfig::volumes`). `dispatch_command()`'s
`Mode::volume`/`Mode::delete_volume`/`Mode::delete_volume_full` cases call these.
`write_config_command()` implements `-w/--write-config`: unlike
`create_volume_command()`/`delete_volume_command()`'s use of
`write_config_file()` (which only ever persists `AppConfig` fields that are
already set), this fills in *every* field before writing — the six
`unshare-*` bools via `.value_or(true)`, and `log_level` from the actually
active `spdlog::get_level()` (not merely a default for when unset — this
also captures an explicit `--log-level` passed alongside `-w` on the same
command line, overriding whatever an existing config file's own
`log-level` already was, since `main()`/`parse_args()` already applied it
in that precedence order by the time this runs) — so a bare `-w` bootstraps
a complete, fully-populated config file for hand-editing, and `-w` combined
with other flags captures their effective values into it. `volumes` is left
exactly as loaded — an open-ended list with no "default" entry to
materialize. Prints the config file's full path (`write_config_file()`
already creates the parent directory and the file itself if missing, so no
separate existence check is needed here).
`run_container()` (the `Mode::run` dispatch case) resolves each `-v` spec
(erroring out, `ok = false`, same as a failed `--user` resolution — `bwrap`
is skipped but unmount/cleanup still runs) into a `ResolvedVolumeMount`,
@@ -814,8 +830,8 @@ Build directory is `buildDir/` (already configured).
full flag list: `-m/--mount`, `-r/--run`, `-u/--umount`, `-c/--cleanup`,
`-l/--list-images`, `-i/--inspect`, `-x/--exec`, `--kill`, `-n/--no-nsenter`, `-D/--daemonize`,
`--user`, `--group`, `--hostname`, `--env`, `--env-file`, `-v/--volume`, `--list-volumes`, `--delete-volume`,
`--delete-volume-full`, `--list-processes`, `--clean-processes`, `-t/--test`, `--log-level`,
`-h/--help`, `-V/--version`)
`--delete-volume-full`, `--list-processes`, `--clean-processes`, `-w/--write-config`,
`-t/--test`, `--log-level`, `-h/--help`, `-V/--version`)
- Run tests: `meson test -C buildDir`
## Code style