From 060a84abda96873596f6f8774c38e4e92f3fdaa2 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 7 Jul 2025 00:29:50 +0200 Subject: [PATCH] test/doc --- sh/code.sh | 20 ++++++++++++++++---- sh/main.sh | 4 ++-- sh/self.sh | 38 -------------------------------------- sh/test.sh | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 44 deletions(-) create mode 100644 sh/test.sh diff --git a/sh/code.sh b/sh/code.sh index 54682bc..c246878 100644 --- a/sh/code.sh +++ b/sh/code.sh @@ -11,10 +11,10 @@ rwx_code() { echo "${_rwx_code}" } -# show the cached aliases -#= rcac -rwx_code_aliases_commands() { - echo "${_rwx_code_aliases_commands}" +# show the cached aliases and functions +#= rcaf +rwx_code_aliases_functions() { + echo "${_rwx_code_aliases_functions}" } # show the cached constants @@ -48,3 +48,15 @@ rwx_code_check() { rwx_log rwx_shellcheck "${RWX_ROOT_SYSTEM}" } + +# fetch matching doc for given name +#= rcd +rwx_code_doc() { + local name="${1}" + [ -n "${name}" ] || return + printf "%s" "${_rwx_code}" | + awk \ + --assign action="doc" \ + --assign target="${name}" \ + --file "${RWX_AWK}" +} diff --git a/sh/main.sh b/sh/main.sh index 0295692..b01c84c 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -206,7 +206,7 @@ _rwx_code_variables="" rwx_parse_code() { # parse aliases commands local line text - _rwx_code_aliases_commands="$(rwx_parse_aliases_commands)" + _rwx_code_aliases_functions="$(rwx_parse_aliases_functions)" while IFS= read -r line; do text="$(echo "${line}" | sed "s| |() { |")" text="${text} \"\${@}\"; }" @@ -221,7 +221,7 @@ EOF # parse variables _rwx_code_variables="$(rwx_parse_variables)" } -rwx_parse_aliases_commands() { +rwx_parse_aliases_functions() { printf "%s" "${_rwx_code}" | awk \ --assign action="alias" \ diff --git a/sh/self.sh b/sh/self.sh index 0588991..0752da9 100644 --- a/sh/self.sh +++ b/sh/self.sh @@ -1,18 +1,6 @@ # self # module -# meta doc -#= rd -rwx_doc() { - local name="${1}" - [ -n "${name}" ] || return - printf "%s" "${_rwx_code}" | - awk \ - --assign action="doc" \ - --assign target="${name}" \ - --file "${RWX_AWK}" -} - # ╭──────┬──────────╮ # │ self │ commands │ # ╰──────┴──────────╯ @@ -109,32 +97,6 @@ rwx_self_subset() { done } -# ╭──────┬──────╮ -# │ self │ test │ -# ╰──────┴──────╯ - -#= rst -rwx_self_test() { - local item - set \ - "main" \ - "alias/git" \ - \ - "RWX_MAIN_NAME" \ - \ - "_rwx_code" \ - \ - "rwx_cache" \ - \ - "alias/batcat" \ - "b" \ - - for item in "${@}"; do - echo - rwx_doc "${item}" - done -} - # ╭──────┬───────╮ # │ self │ write │ # ╰──────┴───────╯ diff --git a/sh/test.sh b/sh/test.sh new file mode 100644 index 0000000..b18a696 --- /dev/null +++ b/sh/test.sh @@ -0,0 +1,33 @@ +# test +# module +# * code +# * doc + +# ╭──────┬──────╮ +# │ test │ code │ +# ╰──────┴──────╯ + +# ╭──────┬─────╮ +# │ test │ doc │ +# ╰──────┴─────╯ + +rwx_test_doc() { + local item + set \ + "main" \ + "alias/git" \ + \ + "RWX_MAIN_NAME" \ + \ + "_rwx_code" \ + \ + "rwx_cache" \ + \ + "alias/batcat" \ + "b" \ + + for item in "${@}"; do + echo + rwx_code_doc "${item}" + done +}