This commit is contained in:
Marc Beninca 2025-07-04 03:35:51 +02:00
parent 3da235e09e
commit 47882c10fe
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F
2 changed files with 47 additions and 33 deletions

View file

@ -8,6 +8,7 @@
# │ main │ constants │ # │ main │ constants │
# ╰──────┴───────────╯ # ╰──────┴───────────╯
# name of the entrypoint file
RWX_MAIN_NAME="main.sh" RWX_MAIN_NAME="main.sh"
RWX_SELF_NAME="rwx" RWX_SELF_NAME="rwx"
@ -61,37 +62,22 @@ rwx_main() {
# │ main │ cache │ # │ main │ cache │
# ╰──────┴───────╯ # ╰──────┴───────╯
RWX_CODE=""
# cache source code of a module
rwx_cache() { rwx_cache() {
local root="${1}" local root="${1}"
local module="${2}" local module="${2}"
local name="${module%.sh}" local name="${module%.sh}"
local path="${root}/${module}" local path="${root}/${module}"
local fill text local text
fill="$(rwx_fill "${#name}")"
text="$(cat "${path}")" text="$(cat "${path}")"
[ -n "${RWX_CODE}" ] && RWX_CODE="${RWX_CODE}
"
RWX_CODE="${RWX_CODE}\ RWX_CODE="${RWX_CODE}\
# ╭───┬────┬─${fill}─╮ #↓ ${name}
# │ ↙ │ sh │ ${name} │
# ╰───┴────┴─${fill}─╯
${text} ${text}
" "
} }
# ╭──────┬──────╮
# │ main │ fill │
# ╰──────┴──────╯
rwx_fill() {
local index="${1}"
while [ "${index}" -gt 0 ]; do
printf "%s" "${2}"
index=$((index - 1))
done
}
# ╭──────┬────────╮ # ╭──────┬────────╮
# │ main │ source │ # │ main │ source │
# ╰──────┴────────╯ # ╰──────┴────────╯

View file

@ -1,22 +1,50 @@
# self module
# meta doc # meta doc
rwx_doc() { rwx_doc() {
local name="${1}" local name="${1}"
[ -n "${name}" ] || return [ -n "${name}" ] || return
local doc line module local constant doc func line module
rwx_ifs_set printf "%s\n" "${RWX_CODE}" | while IFS= read -r line; do
for module in $(rwx_find_shell "${RWX_ROOT_SYSTEM}"); do
while read -r line; do
case "${line}" in case "${line}" in
"#"*) doc="${doc}${line}" ;; "#!"*) doc="" ;;
"${name}() {") "#↓"*)
doc=""
module="$(echo "${line}" | sed "s|#↓ \\(.*\\)|\\1|")"
;;
"#"*)
[ -n "${doc}" ] && doc="${doc}
"
doc="${doc}${line}"
;;
*"="*)
constant="$(echo "${line}" | sed "s|^\\(.*\\)=.*|\\1|")"
if [ "${constant}" = "${name}" ]; then
echo "${doc}" echo "${doc}"
return return
else
doc=""
fi
;;
*"("*")"*"{"*)
func="$(echo "${line}" | sed "s|^\\(.*\\)() {.*|\\1|")"
if [ "${func}" = "${name}" ]; then
echo "${doc}"
return
else
doc=""
fi
;;
*)
if [ "${module}" = "${name}" ]; then
echo "${doc}"
return
else
doc=""
fi
;; ;;
*) doc="" ;;
esac esac
done <"${RWX_ROOT_SYSTEM}/${module}"
done done
rwx_ifs_unset
} }
# ╭──────┬───────╮ # ╭──────┬───────╮