-
-
Notifications
You must be signed in to change notification settings - Fork 710
/
generate-api-docs.sh
48 lines (36 loc) · 1.11 KB
/
generate-api-docs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env bash
set -e
script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
gef_root=$(dirname "$script_dir")
output_path="${gef_root}/docs/api/"
src_base_url="https://github.com/hugsy/gef/blob/main/"
full_doc_path="${gef_root}/docs/api/gef.md"
check()
{
python -c "import lazydocs" || exit 1
}
clean_doc()
{
rm -fr -- "${output_path}/*.md"
}
generate_doc()
{
api="$1"
gdb -q \
-ex "pi from lazydocs.generation import generate_docs" \
-ex "pi generate_docs(paths=['${api}'], output_path='${output_path}')" \
-ex quit
}
fixup_doc()
{
# rename
mv "${output_path}/__main__.md" "${full_doc_path}"
# replace the title
sed -i 's?# <kbd>module</kbd> `__main__`?# <kbd>module</kbd> `GEF`?' "${full_doc_path}"
# fix the hrefs
sed -i -ze 's!<a href="\([^"]*\)[^`]*`\([^`]*\)`!<a href="https://cs.github.com/hugsy/gef?q=\2"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>\n\n## <kbd>function</kbd> `\2`!g' "${full_doc_path}"
}
check
clean_doc
generate_doc "__main__"
fixup_doc