main/main,cache
This commit is contained in:
parent
adef5c0768
commit
cd1701fb71
1 changed files with 61 additions and 59 deletions
120
sh/main.sh
120
sh/main.sh
|
@ -37,65 +37,6 @@ RWX_SELF_USER="${HOME}/${RWX_SELF_NAME}"
|
|||
# path to the entrypoint main file of the project
|
||||
RWX_MAIN_PATH="${RWX_ROOT_SYSTEM}/${RWX_MAIN_NAME}"
|
||||
|
||||
# ╭──────┬──────╮
|
||||
# │ main │ main │
|
||||
# ╰──────┴──────╯
|
||||
|
||||
# run initial steps
|
||||
rwx_main() {
|
||||
# cache main
|
||||
rwx_cache "${RWX_ROOT_SYSTEM}" "${RWX_MAIN_NAME}"
|
||||
# source system root
|
||||
if ! rwx_source "${RWX_ROOT_SYSTEM}" "${RWX_MAIN_NAME}"; then
|
||||
__rwx_log "Not a directory: ${RWX_ROOT_SYSTEM}"
|
||||
return 1
|
||||
fi
|
||||
# source user root
|
||||
rwx_source "${RWX_SELF_USER}"
|
||||
# load code cache
|
||||
rwx_code_load
|
||||
# context / command
|
||||
local command
|
||||
# command name used to run
|
||||
# (stripped from hyphen interactive flag)
|
||||
command="$(basename "${0}" | sed "s|^-||")"
|
||||
case "${command}" in
|
||||
"bash" | "dash" | "sh") unset command ;;
|
||||
*) ;;
|
||||
esac
|
||||
if [ -n "${command}" ]; then
|
||||
local function
|
||||
# find the matching function
|
||||
function="$(rwx_code_alias_function "${command}")"
|
||||
if [ -n "${function}" ]; then
|
||||
"${function}" "${@}"
|
||||
fi
|
||||
# context / shell
|
||||
else
|
||||
rwx_self_init
|
||||
fi
|
||||
}
|
||||
|
||||
# ╭──────┬───────╮
|
||||
# │ main │ cache │
|
||||
# ╰──────┴───────╯
|
||||
|
||||
# cache source code of a module
|
||||
# inside a global code variable
|
||||
rwx_cache() {
|
||||
local root="${1}"
|
||||
local module="${2}"
|
||||
local name="${module%.sh}"
|
||||
local path="${root}/${module}"
|
||||
local text
|
||||
text="$(cat "${path}")"
|
||||
# all source code
|
||||
_rwx_code="${_rwx_code}\
|
||||
#. ${name}
|
||||
${text}
|
||||
"
|
||||
}
|
||||
|
||||
# ╭──────┬────────╮
|
||||
# │ main │ source │
|
||||
# ╰──────┴────────╯
|
||||
|
@ -176,6 +117,67 @@ rwx_find_shell() {
|
|||
rwx_find_extension "sh" "${@}"
|
||||
}
|
||||
|
||||
################################################################################
|
||||
|
||||
# ╭──────┬───────╮
|
||||
# │ main │ cache │
|
||||
# ╰──────┴───────╯
|
||||
|
||||
# cache source code of a module
|
||||
# inside a global code variable
|
||||
rwx_cache() {
|
||||
local root="${1}"
|
||||
local module="${2}"
|
||||
local name="${module%.sh}"
|
||||
local path="${root}/${module}"
|
||||
local text
|
||||
text="$(cat "${path}")"
|
||||
# all source code
|
||||
_rwx_code="${_rwx_code}\
|
||||
#. ${name}
|
||||
${text}
|
||||
"
|
||||
}
|
||||
|
||||
# ╭──────┬──────╮
|
||||
# │ main │ main │
|
||||
# ╰──────┴──────╯
|
||||
|
||||
# run initial steps
|
||||
rwx_main() {
|
||||
# cache main
|
||||
rwx_cache "${RWX_ROOT_SYSTEM}" "${RWX_MAIN_NAME}"
|
||||
# source system root
|
||||
if ! rwx_source "${RWX_ROOT_SYSTEM}" "${RWX_MAIN_NAME}"; then
|
||||
__rwx_log "Not a directory: ${RWX_ROOT_SYSTEM}"
|
||||
return 1
|
||||
fi
|
||||
# source user root
|
||||
rwx_source "${RWX_SELF_USER}"
|
||||
# load code cache
|
||||
rwx_code_load
|
||||
# context / command
|
||||
local command
|
||||
# command name used to run
|
||||
# (stripped from hyphen interactive flag)
|
||||
command="$(basename "${0}" | sed "s|^-||")"
|
||||
case "${command}" in
|
||||
"bash" | "dash" | "sh") unset command ;;
|
||||
*) ;;
|
||||
esac
|
||||
if [ -n "${command}" ]; then
|
||||
local function
|
||||
# find the matching function
|
||||
function="$(rwx_code_alias_function "${command}")"
|
||||
if [ -n "${function}" ]; then
|
||||
"${function}" "${@}"
|
||||
fi
|
||||
# context / shell
|
||||
else
|
||||
rwx_self_init
|
||||
fi
|
||||
}
|
||||
|
||||
# ╭──────┬─────╮
|
||||
# │ main │ run │
|
||||
# ╰──────┴─────╯
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue