Skip to content

Commit 939abed

Browse files
authored
Merge pull request #1173 from onekey-sec/handlers-doc
Automated generation of handlers documentation
2 parents 9ea1060 + 0bad94a commit 939abed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+3122
-63
lines changed

.just/doc.just

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
set working-directory := ".."
2+
3+
# mkdocs defaults
4+
site-directory := "./site"
5+
dev-address := "localhost:8000"
6+
7+
## Help
8+
help: (_mod_help source_file())
9+
10+
_mod_help justfile:
11+
@{{ just_executable() }} -f {{ justfile }} --list --unsorted
12+
13+
## Logging
14+
_info message:
15+
@printf "{{BOLD}}--> {{message}}{{NORMAL}}\n"
16+
17+
_success message="Task finished successfully":
18+
@printf "{{GREEN}}--> ✔ {{message}}{{NORMAL}}\n"
19+
20+
_error message:
21+
@printf "{{RED}}--> ✘ {{message}}{{NORMAL}}\n"
22+
23+
# Prints this help
24+
25+
_install_dependencies: (_info "Installing documentation related dependencies") && (_success "Documentation related dependencies are installed")
26+
uv sync --frozen --all-extras --group docs
27+
28+
# Build documentation to html
29+
build *mkdocs-args: _install_dependencies (_info "Building documentation") && (_success "Documentation built to " + site-directory + " directory")
30+
uv run mkdocs build -q --site-dir {{ site-directory }} {{ mkdocs-args }}
31+
32+
# Open documentation in browser
33+
open *mkdocs-args: _install_dependencies (_info "Running mkdocs server listening at " + dev-address + ". Press CTRL-C to exit")
34+
uv run mkdocs serve -q --dev-addr {{ dev-address }} --open {{ mkdocs-args }}
35+
36+
# Generate Handler markdowns
37+
generate-handlers-doc:
38+
#!/usr/bin/env python
39+
from pathlib import Path
40+
41+
from unblob.doc import generate_markdown
42+
from unblob.handlers import BUILTIN_HANDLERS
43+
44+
FORMAT_TABLE_HEADERS = """| Format | Type | Fully supported? |\n| :------------ | :----------------------------------- | :-----------------: |\n"""
45+
46+
sorted_handlers = sorted(BUILTIN_HANDLERS, key=lambda handler_class: handler_class.NAME)
47+
handlers_path = Path("docs/handlers.md")
48+
print(f"Generating: {handlers_path}")
49+
with handlers_path.open("w") as f:
50+
f.write(FORMAT_TABLE_HEADERS)
51+
52+
for handler_class in sorted_handlers:
53+
support_icon = "octicons-check-16" if handler_class.DOC.fully_supported else "octicons-alert-fill-12"
54+
f.write(f"""| [`{handler_class.DOC.name.upper()}`](#{handler_class.DOC.name.replace(" ", "-").lower()}) | {handler_class.DOC.handler_type.name} | :{support_icon}: |\n""")
55+
56+
for handler_class in sorted_handlers:
57+
content = generate_markdown(handler_class.DOC)
58+
f.write("\n" + content)

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ repos:
1111
- id: check-json
1212
- id: check-toml
1313
- id: check-yaml
14+
args: ['--unsafe']
1415
- id: check-added-large-files
1516

1617
- repo: local

0 commit comments

Comments
 (0)