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}" \ --assign action="${action}" \
"${_rwx_code_awk}" "${_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 │
# ╰──────╯ # ╰──────╯
# main module # main module
# * builtins
# * echo
# * printf
# * read
# * binaries
# * awk
# * cat
# * find
# * sed
# ╭──────┬───────────╮ # ╭──────┬───────────╮
# │ main │ constants │ # │ main │ constants │
@ -29,6 +20,7 @@ RWX_SELF_NAME="rwx"
# cache of all sourced code modules # cache of all sourced code modules
_rwx_code="" _rwx_code=""
# 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}"
# user root directory of the project # user root directory of the project
@ -145,6 +137,7 @@ ${text}
# ╰──────┴──────╯ # ╰──────┴──────╯
# run initial steps # run initial steps
#< code
rwx_main() { rwx_main() {
# cache main # cache main
rwx_cache "${RWX_ROOT_SYSTEM}" "${RWX_MAIN_NAME}" rwx_cache "${RWX_ROOT_SYSTEM}" "${RWX_MAIN_NAME}"
@ -153,30 +146,8 @@ rwx_main() {
__rwx_log "Not a directory: ${RWX_ROOT_SYSTEM}" __rwx_log "Not a directory: ${RWX_ROOT_SYSTEM}"
return 1 return 1
fi fi
# source user root # run code main function
rwx_source "${RWX_SELF_USER}" rwx_code_main
# 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
} }
# ╭──────┬─────╮ # ╭──────┬─────╮