first
This commit is contained in:
42
core/registry.sh
Normal file
42
core/registry.sh
Normal file
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
REGISTRY_MODULE_COUNT=0
|
||||
declare -a REGISTRY_MODULES=()
|
||||
declare -A REGISTRY_MODULE_PATHS=()
|
||||
|
||||
registry_init() {
|
||||
local module_file=""
|
||||
local module_id=""
|
||||
REGISTRY_MODULE_COUNT=0
|
||||
REGISTRY_MODULES=()
|
||||
REGISTRY_MODULE_PATHS=()
|
||||
|
||||
while IFS= read -r module_file; do
|
||||
# shellcheck source=/dev/null
|
||||
source "$module_file"
|
||||
module_id="${module_file#"$RUNTIME_PROJECT_ROOT/modules/"}"
|
||||
module_id="${module_id%/module.sh}"
|
||||
REGISTRY_MODULES+=("$module_id")
|
||||
REGISTRY_MODULE_PATHS["$module_id"]="$module_file"
|
||||
done < <(find "$RUNTIME_PROJECT_ROOT/modules" -mindepth 3 -maxdepth 3 -type f -name 'module.sh' | sort)
|
||||
|
||||
REGISTRY_MODULE_COUNT="${#REGISTRY_MODULES[@]}"
|
||||
}
|
||||
|
||||
registry_summary() {
|
||||
printf '%s' "$REGISTRY_MODULE_COUNT"
|
||||
}
|
||||
|
||||
registry_list() {
|
||||
printf '%s\n' "${REGISTRY_MODULES[@]}"
|
||||
}
|
||||
|
||||
registry_has_module() {
|
||||
local module_id="$1"
|
||||
[[ -n "${REGISTRY_MODULE_PATHS[$module_id]:-}" ]]
|
||||
}
|
||||
|
||||
registry_module_path() {
|
||||
local module_id="$1"
|
||||
printf '%s\n' "${REGISTRY_MODULE_PATHS[$module_id]:-}"
|
||||
}
|
||||
Reference in New Issue
Block a user