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
|
||||
RWX_SELF_USER="${HOME}/${RWX_SELF_NAME}"
|
||||
|
||||
# cache of all sourced code modules
|
||||
_rwx_code=""
|
||||
# cache for the parsing awk script
|
||||
_rwx_code_awk="$(cat "${RWX_ROOT_SYSTEM}/core/code.awk")"
|
||||
# cache for code aliases
|
||||
|
@ -223,8 +225,34 @@ rwx_code_parse() {
|
|||
# ╰──────┴──────╯
|
||||
|
||||
rwx_code_main() {
|
||||
# source user root
|
||||
rwx_main_source "${RWX_SELF_USER}"
|
||||
local modules_main="${1}"
|
||||
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
|
||||
rwx_code_load
|
||||
# set command
|
||||
|
|
67
sh/main.sh
67
sh/main.sh
|
@ -20,9 +20,6 @@ RWX_SELF_NAME="rwx"
|
|||
# │ main │ variables │
|
||||
# ╰──────┴───────────╯
|
||||
|
||||
# cache of all sourced code modules
|
||||
_rwx_code=""
|
||||
|
||||
# TODO variablize
|
||||
# system root directory of the project
|
||||
RWX_ROOT_SYSTEM="/usr/local/lib/${RWX_SELF_NAME}"
|
||||
|
@ -72,52 +69,6 @@ _rwx_main_log() {
|
|||
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 │
|
||||
# ╰──────┴──────╯
|
||||
|
@ -125,13 +76,19 @@ ${text}
|
|||
# run initial steps
|
||||
#< core/code
|
||||
rwx_main_main() {
|
||||
# source system root
|
||||
if ! rwx_main_source "${RWX_ROOT_SYSTEM}" "${RWX_MAIN_NAME}"; then
|
||||
_rwx_main_log "Not a directory: ${RWX_ROOT_SYSTEM}"
|
||||
return 1
|
||||
fi
|
||||
local module modules
|
||||
# find & source modules
|
||||
modules="$(rwx_main_find "${RWX_ROOT_SYSTEM}")"
|
||||
while IFS= read -r module; do
|
||||
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
|
||||
rwx_code_main "${@}"
|
||||
rwx_code_main "${modules}" "${@}"
|
||||
}
|
||||
|
||||
# run main function
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue