code/main

This commit is contained in:
Marc Beninca 2025-07-08 04:35:32 +02:00
parent 389f73a0b9
commit d9a6e33409
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F
2 changed files with 35 additions and 33 deletions

View file

@ -181,3 +181,34 @@ rwx_code_parse() {
--assign action="${action}" \
"${_rwx_code_awk}"
}
# ╭──────┬──────╮
# │ code │ main │
# ╰──────┴──────╯
rwx_code_main() {
# 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
}

View file

@ -3,15 +3,6 @@
# │ main │
# ╰──────╯
# main module
# * builtins
# * echo
# * printf
# * read
# * binaries
# * awk
# * cat
# * find
# * sed
# ╭──────┬───────────╮
# │ main │ constants │
@ -29,6 +20,7 @@ RWX_SELF_NAME="rwx"
# 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}"
# user root directory of the project
@ -145,6 +137,7 @@ ${text}
# ╰──────┴──────╯
# run initial steps
#< code
rwx_main() {
# cache main
rwx_cache "${RWX_ROOT_SYSTEM}" "${RWX_MAIN_NAME}"
@ -153,30 +146,8 @@ rwx_main() {
__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
# run code main function
rwx_code_main
}
# ╭──────┬─────╮