This commit is contained in:
parent
09bf59c3ba
commit
0e9108999d
2 changed files with 42 additions and 57 deletions
|
@ -12,6 +12,8 @@ RWX_MAIN_PATH="${RWX_ROOT_SYSTEM}/${RWX_MAIN_NAME}.${RWX_MAIN_EXTENSION}"
|
||||||
# user root directory of the project
|
# user root directory of the project
|
||||||
RWX_SELF_USER="${HOME}/${RWX_SELF_NAME}"
|
RWX_SELF_USER="${HOME}/${RWX_SELF_NAME}"
|
||||||
|
|
||||||
|
# cache of all sourced code modules
|
||||||
|
_rwx_code=""
|
||||||
# cache for the parsing awk script
|
# cache for the parsing awk script
|
||||||
_rwx_code_awk="$(cat "${RWX_ROOT_SYSTEM}/core/code.awk")"
|
_rwx_code_awk="$(cat "${RWX_ROOT_SYSTEM}/core/code.awk")"
|
||||||
# cache for code aliases
|
# cache for code aliases
|
||||||
|
@ -223,8 +225,34 @@ rwx_code_parse() {
|
||||||
# ╰──────┴──────╯
|
# ╰──────┴──────╯
|
||||||
|
|
||||||
rwx_code_main() {
|
rwx_code_main() {
|
||||||
# source user root
|
local modules_main="${1}"
|
||||||
rwx_main_source "${RWX_SELF_USER}"
|
local module modules_user
|
||||||
|
# find & source modules
|
||||||
|
modules_user="$(rwx_main_find "${RWX_SELF_USER}")"
|
||||||
|
while IFS= read -r module; do
|
||||||
|
# shellcheck disable=SC1090
|
||||||
|
. "${RWX_SELF_USER}/${module}.${RWX_MAIN_EXTENSION}"
|
||||||
|
done <<EOF
|
||||||
|
${modules_user}
|
||||||
|
EOF
|
||||||
|
# cache main modules
|
||||||
|
while IFS= read -r module; do
|
||||||
|
# cache main module
|
||||||
|
_rwx_code="${_rwx_code}#. ${module}
|
||||||
|
$(cat "${RWX_ROOT_SYSTEM}/${module}.${RWX_MAIN_EXTENSION}")
|
||||||
|
"
|
||||||
|
done <<EOF
|
||||||
|
${modules_main}
|
||||||
|
EOF
|
||||||
|
# cache modules
|
||||||
|
while IFS= read -r module; do
|
||||||
|
# cache module
|
||||||
|
_rwx_code="${_rwx_code}#. ${module}
|
||||||
|
$(cat "${RWX_SELF_USER}/${module}.${RWX_MAIN_EXTENSION}")
|
||||||
|
"
|
||||||
|
done <<EOF
|
||||||
|
${modules_user}
|
||||||
|
EOF
|
||||||
# load code cache
|
# load code cache
|
||||||
rwx_code_load
|
rwx_code_load
|
||||||
# set command
|
# set command
|
||||||
|
|
67
sh/main.sh
67
sh/main.sh
|
@ -20,9 +20,6 @@ RWX_SELF_NAME="rwx"
|
||||||
# │ main │ variables │
|
# │ main │ variables │
|
||||||
# ╰──────┴───────────╯
|
# ╰──────┴───────────╯
|
||||||
|
|
||||||
# cache of all sourced code modules
|
|
||||||
_rwx_code=""
|
|
||||||
|
|
||||||
# TODO variablize
|
# TODO variablize
|
||||||
# system root directory of the project
|
# system root directory of the project
|
||||||
RWX_ROOT_SYSTEM="/usr/local/lib/${RWX_SELF_NAME}"
|
RWX_ROOT_SYSTEM="/usr/local/lib/${RWX_SELF_NAME}"
|
||||||
|
@ -72,52 +69,6 @@ _rwx_main_log() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# ╭──────┬────────╮
|
|
||||||
# │ main │ source │
|
|
||||||
# ╰──────┴────────╯
|
|
||||||
|
|
||||||
# source code from root path
|
|
||||||
rwx_main_source() {
|
|
||||||
local root="${1}"
|
|
||||||
local main="${2}"
|
|
||||||
[ -d "${root}" ] ||
|
|
||||||
return 1
|
|
||||||
local module modules
|
|
||||||
# cache main
|
|
||||||
[ -n "${main}" ] && rwx_main_cache "${root}" "${main}"
|
|
||||||
modules="$(rwx_main_find "${root}")"
|
|
||||||
while IFS= read -r module; do
|
|
||||||
if [ "${module}" != "${main}" ]; then
|
|
||||||
# shellcheck disable=SC1090
|
|
||||||
. "${root}/${module}.${RWX_MAIN_EXTENSION}"
|
|
||||||
# cache code
|
|
||||||
rwx_main_cache "${root}" "${module}"
|
|
||||||
fi
|
|
||||||
done <<EOF
|
|
||||||
${modules}
|
|
||||||
EOF
|
|
||||||
}
|
|
||||||
|
|
||||||
# ╭──────┬───────╮
|
|
||||||
# │ main │ cache │
|
|
||||||
# ╰──────┴───────╯
|
|
||||||
|
|
||||||
# cache source code of a module
|
|
||||||
# inside a global code variable
|
|
||||||
#| cat
|
|
||||||
rwx_main_cache() {
|
|
||||||
local root="${1}"
|
|
||||||
local module="${2}"
|
|
||||||
local path="${root}/${module}.${RWX_MAIN_EXTENSION}"
|
|
||||||
local text
|
|
||||||
text="$(cat "${path}")"
|
|
||||||
# all source code
|
|
||||||
_rwx_code="${_rwx_code}\
|
|
||||||
#. ${module}
|
|
||||||
${text}
|
|
||||||
"
|
|
||||||
}
|
|
||||||
|
|
||||||
# ╭──────┬──────╮
|
# ╭──────┬──────╮
|
||||||
# │ main │ main │
|
# │ main │ main │
|
||||||
# ╰──────┴──────╯
|
# ╰──────┴──────╯
|
||||||
|
@ -125,13 +76,19 @@ ${text}
|
||||||
# run initial steps
|
# run initial steps
|
||||||
#< core/code
|
#< core/code
|
||||||
rwx_main_main() {
|
rwx_main_main() {
|
||||||
# source system root
|
local module modules
|
||||||
if ! rwx_main_source "${RWX_ROOT_SYSTEM}" "${RWX_MAIN_NAME}"; then
|
# find & source modules
|
||||||
_rwx_main_log "Not a directory: ${RWX_ROOT_SYSTEM}"
|
modules="$(rwx_main_find "${RWX_ROOT_SYSTEM}")"
|
||||||
return 1
|
while IFS= read -r module; do
|
||||||
fi
|
if [ "${module}" != "${RWX_MAIN_NAME}" ]; then
|
||||||
|
# shellcheck disable=SC1090
|
||||||
|
. "${RWX_ROOT_SYSTEM}/${module}.${RWX_MAIN_EXTENSION}"
|
||||||
|
fi
|
||||||
|
done <<EOF
|
||||||
|
${modules}
|
||||||
|
EOF
|
||||||
# run code main function
|
# run code main function
|
||||||
rwx_code_main "${@}"
|
rwx_code_main "${modules}" "${@}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# run main function
|
# run main function
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue