From 493f8aa11ce49572fa23ac06ebde323b470e1623 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 28 Jun 2026 09:47:22 +0300 Subject: mr0: add CONFIG_SPECS registry; derive defaults, CLI targets, print, validation Introduce src/lib/config.spec.source.sh: CONFIG_SPECS, a single '|'-delimited config-field registry (name|default|has_default|cli_overridable|validation| print_kind), using the same spec idiom as ACTION_SPECS / TEMPLATE_RENDER_FIELD_SPECS. This replaces the parallel, hand-maintained config-knowledge lists that caused the TARBALL_INCLUDE default-drift bug (fixed in 7r0). Derived consumers (behaviour byte-identical): - apply_config_defaults: loops the registry applying VAR="${VAR:-default}" for has_default=yes scalars; arrays keep their declare -p guards. - CLI_CONFIG_OVERRIDE_TARGETS: built from cli_overridable=yes (verified to match CLI_OPTION_SPEC's config= targets exactly). - print_config: emits in registry order dispatching on print_kind. - validate_common_config: required set + per-field rule come from the registry via config_spec_validation + validate_config_field_required/_kind; two-phase order and historical reporting order preserved. log_configured_action and the dry-run plan are not yet converted (bespoke prose / intermixed computed values). shellcheck: TARBALL_SUFFIX lost its visible literal assignment, annotated at the archive use site. Co-Authored-By: Claude Opus 4.8 --- src/lib/config.source.sh | 67 ++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 33 deletions(-) (limited to 'src/lib/config.source.sh') diff --git a/src/lib/config.source.sh b/src/lib/config.source.sh index c676899..b08aec9 100644 --- a/src/lib/config.source.sh +++ b/src/lib/config.source.sh @@ -43,40 +43,41 @@ missing_config() { exit 1 } +# Apply the documented defaults for every config field that has one. Driven +# entirely by CONFIG_SPECS (task mr0): each scalar entry with has_default=yes +# gets VAR="${VAR:-$default}" applied, so a field's default value lives in +# exactly one place (the registry) instead of being restated here. This is what +# eliminates the default-drift class of bug (TARBALL_INCLUDE once read 'no' here +# while the registry/default-conf said 'yes', fixed in 7r0): the default and the +# documented value can no longer disagree because they are the same datum. +# +# Notes: +# - Empty defaults are intentional and applied verbatim (e.g. FAVICON='' means +# "use the bundled default favicon"; HEIGHT/RANDOM_SEED/ORIGINAL_BASEPATH +# default to the empty string). +# - has_default=no scalars (TITLE, THUMBHEIGHT, MAXPREVIEWS, ...) are required +# and deliberately get no default; validate_common_config rejects them when +# unset. +# - The two array fields (TAR_OPTS, SYNC_DESTINATIONS) cannot use the scalar +# "${VAR:-...}" form, so they keep their `declare -p` guards below. They are +# marked print_kind=array / has_default=no in the registry so this loop +# skips them. apply_config_defaults() { - # Empty FAVICON means use the bundled default favicon; otherwise it is a path - # to a custom favicon file copied into the album as favicon.ico. - FAVICON="${FAVICON:-}" - HEIGHT="${HEIGHT:-}" - IMAGE_JOBS="${IMAGE_JOBS:-3}" - IMAGEMAGICK_TIMEOUT="${IMAGEMAGICK_TIMEOUT:-60}" - ORIGINAL_BASEPATH="${ORIGINAL_BASEPATH:-}" - RANDOM_SEED="${RANDOM_SEED:-}" - SHUFFLE="${SHUFFLE:-no}" - # SOURCE_URL is the project/source link shown in the page header bar ("Site - # generated ... with "). Defaults to the shuriken.sh repo; - # override it per site (e.g. to the album's own repo) via config or - # --source-url. The header bar derives the displayed text from the URL itself. - SOURCE_URL="${SOURCE_URL:-https://codeberg.org/snonux/shuriken.sh}" - SPLASH_PAGE="${SPLASH_PAGE:-yes}" - STATS_PAGE="${STATS_PAGE:-no}" - # Optional with a default (unlike the required THUMBHEIGHT): the percent - # chance a preview tile is subdivided into smaller thumbnails, and the - # percent chance it becomes a large 2x2 "feature" tile. 0 disables either. - THUMB_SUBDIVIDE_PERCENT="${THUMB_SUBDIVIDE_PERCENT:-30}" - THUMB_FEATURE_PERCENT="${THUMB_FEATURE_PERCENT:-10}" - SYNC_DELETE="${SYNC_DELETE:-yes}" - # Per-destination rsync timeout (seconds), mirroring TAR_TIMEOUT/ - # IMAGEMAGICK_TIMEOUT. Each destination in sync_dist is wrapped in - # run_with_timeout so a hung/unreachable mirror cannot block the whole sync. - SYNC_TIMEOUT="${SYNC_TIMEOUT:-300}" - # Default 'yes': a tarball of the incoming dir is included in the dist unless - # disabled. This must match the documented default in shuriken.default.conf - # (TARBALL_INCLUDE=yes) -- it previously drifted to 'no' here. 'yes' is the - # original, authoritative default (tarball inclusion was on from the start). - TARBALL_INCLUDE="${TARBALL_INCLUDE:-yes}" - TARBALL_SUFFIX="${TARBALL_SUFFIX:-.tar}" - TAR_TIMEOUT="${TAR_TIMEOUT:-120}" + local spec + local -a fields=() + local name default has_default + + for spec in "${CONFIG_SPECS[@]}"; do + config_spec_split "$spec" fields + name="${fields[0]}" + default="${fields[1]}" + has_default="${fields[2]}" + + if [ "$has_default" = yes ]; then + printf -v "$name" '%s' "${!name:-$default}" + fi + done + if ! declare -p TAR_OPTS >/dev/null 2>&1; then TAR_OPTS=(-c) fi -- cgit v1.2.3