From 4b62df10512b8827c74452046e10328ab6895aed Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Sat, 26 Nov 2022 11:44:48 +0100 Subject: [PATCH] Generate message type doc --- scripts/hooks.sh | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/scripts/hooks.sh b/scripts/hooks.sh index dae60af..e9f1c4b 100755 --- a/scripts/hooks.sh +++ b/scripts/hooks.sh @@ -25,6 +25,32 @@ function get_hooks() { grep -o "^[[:space:]]*def on_.*(&block)" "$ruby_file" | grep -o "on_[^(]*" | awk NF } +function get_msg_of_client_hook() { + local hook="$1" + local line + local ifs="$IFS" + local in_func=0 + while IFS='' read -r line + do + if [ "$line" == " def $hook(chunk)" ] + then + in_func=1 + fi + if [[ "$line" =~ " end" ]] + then + in_func=0 + fi + if [ "$in_func" == "1" ] + then + if [[ "$line" =~ message\ =\ (.*).new ]] + then + echo "${BASH_REMATCH[1]}" + fi + fi + done < lib/game_client.rb + IFS="$ifs" +} + function add_hook_doc() { local mdfile="$1" local ruby_class="$2" @@ -53,6 +79,13 @@ function add_hook_doc() { obj_var=server run="server.run('127.0.0.1', 8377)" fi + local doc_text='TODO: generated documentation' + local msg_class + msg_class="$(get_msg_of_client_hook "$hook")" + if [ "$msg_class" != "" ] + then + doc_text="context.message is a [$msg_class](../classes/messages/$msg_class.md)" + fi tmpdoc="$tmpdir/doc.md" { head -n "$class_ln" "$mdfile" @@ -65,7 +98,7 @@ function add_hook_doc() { **Parameter: block [Block |[context](../classes/Context.md)|]** - TODO: generated documentation + $doc_text **Example:** EOF