Config Module
This module provides a priority-based configuration loading system and reusable validation hooks for the root script.
Module Overview
- Purpose: Provide a priority-based configuration loading system and reusable validation hooks for the root script.
- Primary modules:
src/lib/config/loader.sh: configuration file parsing and prioritized loadingsrc/lib/config/validator.sh: required environment variable validation (non-fatal; returns status)
Configuration Priority System
Configuration values may come from:
- Environment variables (highest precedence)
- Home config:
~/.bearflare/.config - Project config:
.env(project root)
The system is implemented by loading config files in order, but only assigning variables that are not already set.
Dependencies
src/lib/logging/logger.sh:log(),log_with_timing()src/lib/utils/timing.sh:now_ns()
Public API
load_config_file(file_path)
Parse a config file and export values, but only for keys not already set in the environment. File format: KEY=VALUE or KEY="VALUE" (double quotes are stripped). Blank lines and # comments are ignored.
load_all_configs()
Load all supported configuration files using the priority system. Files: ~/.bearflare/.config, .env. May export environment variables and prints "Configuration loaded from …" info to stdout when applicable.
validate_required_env_vars()
Validate that required Cloudflare env vars exist without exiting. Checks: CLOUDFLARE_ACCOUNT_ID, CLOUDFLARE_API_TOKEN, CLOUDFLARE_D1_DATABASE_ID. Returns non-zero when any are missing (caller decides whether to exit).
Recommended Integration Pattern
In bearflare.sh:
- Source modules (core/timing/logging/config).
- Initialize logging (
init_logging) early. - Call
load_all_configsto populate values. - Call
validate_required_env_varsand handle its return:- If non-zero: print usage and exit with code
1.
- If non-zero: print usage and exit with code
Navigation
- Architecture Overview - High-level architecture
- Modular Architecture - Module hierarchy and dependencies
- CLI Module - Command-line interface
- Logging Module - Logging system