Generate message type doc

This commit is contained in:
ChillerDragon 2022-11-26 11:44:48 +01:00
parent 6cad2f6bbc
commit 4b62df1051

View file

@ -25,6 +25,32 @@ function get_hooks() {
grep -o "^[[:space:]]*def on_.*(&block)" "$ruby_file" | grep -o "on_[^(]*" | awk NF 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() { function add_hook_doc() {
local mdfile="$1" local mdfile="$1"
local ruby_class="$2" local ruby_class="$2"
@ -53,6 +79,13 @@ function add_hook_doc() {
obj_var=server obj_var=server
run="server.run('127.0.0.1', 8377)" run="server.run('127.0.0.1', 8377)"
fi 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" tmpdoc="$tmpdir/doc.md"
{ {
head -n "$class_ln" "$mdfile" head -n "$class_ln" "$mdfile"
@ -65,7 +98,7 @@ function add_hook_doc() {
**Parameter: block [Block |[context](../classes/Context.md)|]** **Parameter: block [Block |[context](../classes/Context.md)|]**
TODO: generated documentation $doc_text
**Example:** **Example:**
EOF EOF