aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/docs
diff options
context:
space:
mode:
author简律纯 <i@jyunko.cn>2023-10-07 07:49:33 +0800
committer简律纯 <i@jyunko.cn>2023-10-07 07:49:33 +0800
commit4b174b5b5646f748a9cd1bba33c7e4f9b247eecb (patch)
tree449c75ad7b2278208de946b28819af25cfe39667 /docs
parent1d61716d07eafa928a90bb51e311d5a66778cad6 (diff)
downloadinfini-4b174b5b5646f748a9cd1bba33c7e4f9b247eecb.tar.gz
infini-4b174b5b5646f748a9cd1bba33c7e4f9b247eecb.zip
feat(docs): version update
Diffstat (limited to 'docs')
-rw-r--r--docs/CLI/index.md63
-rw-r--r--docs/Core/index.md11
-rw-r--r--docs/blog/posts/rules-class-just-landed.md8
3 files changed, 72 insertions, 10 deletions
diff --git a/docs/CLI/index.md b/docs/CLI/index.md
index c31a0bc9..cc619ae4 100644
--- a/docs/CLI/index.md
+++ b/docs/CLI/index.md
@@ -1 +1,64 @@
# CLI Reference
+
+```python exec="1" idprefix=""
+import argparse
+import re
+from HydroRollCore import Cli
+
+parser = Cli().parser
+
+MONOSPACED = ("pyproject.toml", "pdm.lock", ".pdm-python", ":pre", ":post", ":all")
+
+def clean_help(help: str) -> str:
+ # Make dunders monospaced avoiding italic markdown rendering
+ help = re.sub(r"__([\w\d\_]+)__", r"`__\1__`", help)
+ # Make env vars monospaced
+ help = re.sub(r"env var: ([A-Z_]+)", r"env var: `\1`", help)
+ for monospaced in MONOSPACED:
+ help = re.sub(rf"\s(['\"]?{monospaced}['\"]?)", f"`{monospaced}`", help)
+ return help
+
+
+def render_parser(
+ parser: argparse.ArgumentParser, title: str, heading_level: int = 2
+) -> str:
+ """Render the parser help documents as a string."""
+ result = [f"{'#' * heading_level} {title}\n"]
+ if parser.description and title != "HydroRollCore":
+ result.append("> " + parser.description + "\n")
+
+ for group in sorted(
+ parser._action_groups, key=lambda g: g.title.lower(), reverse=True
+ ):
+ if not any(
+ bool(action.option_strings or action.dest)
+ or isinstance(action, argparse._SubParsersAction)
+ for action in group._group_actions
+ ):
+ continue
+
+ result.append(f"{group.title.title()}:\n")
+ for action in group._group_actions:
+ if isinstance(action, argparse._SubParsersAction):
+ for name, subparser in action._name_parser_map.items():
+ result.append(render_parser(subparser, name, heading_level + 1))
+ continue
+
+ opts = [f"`{opt}`" for opt in action.option_strings]
+ if not opts:
+ line = f"- `{action.dest}`"
+ else:
+ line = f"- {', '.join(opts)}"
+ if action.metavar:
+ line += f" `{action.metavar}`"
+ line += f": {clean_help(action.help)}"
+ if action.default and action.default != argparse.SUPPRESS:
+ line += f" (default: `{action.default}`)"
+ result.append(line)
+ result.append("")
+
+ return "\n".join(result)
+
+
+print(render_parser(parser, "HydroRollCore"))
+``` \ No newline at end of file
diff --git a/docs/Core/index.md b/docs/Core/index.md
index 3f3422b6..aff4930b 100644
--- a/docs/Core/index.md
+++ b/docs/Core/index.md
@@ -21,7 +21,7 @@
``` shell
git clone https://github.com/HydroRoll-Team/HydroRollCore.git
cd HydroRollCore
-poetry install --no-dev
+pdm install
# 或者使用pip
# pip install HydroRollCore
```
@@ -30,16 +30,17 @@ poetry install --no-dev
``` shell
mkdir myrules && cd myrules && mkdir rule1
-echo.> config.toml && echo.> __init__.py :: 创建空的配置文件和python运行脚本
+echo.> config.toml
+echo.> __init__.py
```
在 `__init__.py` 创建一个 `rule` 实例并继承 `Rule` 基类, 通过编写合适的相关方法与类注册规则包实现规则的自定义。
``` python
-from HydroRollCore import Rules
+from HydroRollCore import Rule
-class Myrule(Rules):
- """自设规则包,继承 Rules 基类"""
+class Myrule(Rule):
+ """自设规则包,继承 Rule 基类"""
```
3. 合理修改你的 `config.toml` 配置文件,完成注册!
diff --git a/docs/blog/posts/rules-class-just-landed.md b/docs/blog/posts/rules-class-just-landed.md
index 705c23b9..b258364c 100644
--- a/docs/blog/posts/rules-class-just-landed.md
+++ b/docs/blog/posts/rules-class-just-landed.md
@@ -2,16 +2,14 @@
date: 2023-10-07
authors: [HsiangNianian]
description: >
- Our new blog is built with the brand new built-in blog plugin. You can build
- a blog alongside your documentation or standalone
+ Rule 基类已经支持泛型了。
categories:
- Rules
links:
- - setup/setting-up-a-blog.md
- - plugins/blog.md
+ - standard/what-is-rule-package
---
-# Blog support just landed
+# Rule 基类已经支持泛型了
__Hey there! You're looking at our new blog, built with the brand new
[built-in blog plugin]. With this plugin, you can easily build a blog alongside