rwx/sh/main.sh
Marc Beninca 7a8915682d
All checks were successful
/ job (push) Successful in 2m58s
main/comments
2025-07-09 23:12:57 +02:00

71 lines
1.7 KiB
Bash
Executable file

#! /usr/bin/env sh
# ╭──────╮
# │ main │
# ╰──────╯
# ╭──────┬───────────╮
# │ main │ constants │
# ╰──────┴───────────╯
# project parent directory
RWX_MAIN_PARENT="/usr/local/lib"
# project name
RWX_MAIN_NAME="rwx"
# project entrypoint module
RWX_MAIN_MODULE="main"
# shell modules extension
RWX_MAIN_EXTENSION="sh"
# ╭──────┬───────────╮
# │ main │ variables │
# ╰──────┴───────────╯
# project main root directory
rwx_main_root="${RWX_MAIN_PARENT}/${RWX_MAIN_NAME}"
# ╭──────┬──────╮
# │ main │ find │
# ╰──────┴──────╯
# find root directory shell modules
#| find
#| sed
#| sort
rwx_main_find() {
local root="${1}"
find \
"${root}" \
-name "*.${RWX_MAIN_EXTENSION}" \
-type "f" \
-printf "%P\n" |
sed "s|\\.[^.]*\$||" |
sort
}
# ╭──────┬──────╮
# │ main │ main │
# ╰──────┴──────╯
# run required initial steps
#< core/code
rwx_main_main() {
local module
local modules
# find main modules
modules="$(rwx_main_find "${rwx_main_root}")"
# source main modules
while IFS= read -r module; do
# except currently running main module
if [ "${module}" != "${RWX_MAIN_MODULE}" ]; then
# shellcheck disable=SC1090
. "${rwx_main_root}/${module}.${RWX_MAIN_EXTENSION}"
fi
done <<EOF
${modules}
EOF
# run code module main function with found main modules
rwx_code_main "${modules}" "${@}"
}
# run main function
rwx_main_main "${@}"