Skip to content

Commit

Permalink
feat(doc): add content field
Browse files Browse the repository at this point in the history
  • Loading branch information
fu050409 committed Mar 19, 2024
1 parent acfb6d8 commit b1f1500
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/infini/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
class Annotation(TypedDict, total=False):
usage: Optional[str]
description: Optional[str]
content: Optional[str]
epilog: Optional[str]
var_doc: Dict[str, str]
sub_cmd: Dict[str, str]
sub_cmd: Dict[str, "Annotation"]


class Doc:
Expand Down
18 changes: 15 additions & 3 deletions src/infini/register.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from infini.doc import Doc
from infini.doc import Annotation, Doc
from infini.typing import List, Dict, Any, Callable, RouterType, Optional, Union, Type
from infini.input import Input
from infini.output import Output
Expand Down Expand Up @@ -34,11 +34,12 @@ def pre_interceptor(
namespace: Optional[str] = None,
usage: Optional[str] = None,
description: Optional[str] = None,
content: Optional[str] = None,
epilog: Optional[str] = None,
):
"""注册一个文本输入拦截器"""

def decorator(func):
def decorator(func: Callable):
@wraps(func)
def wrapper(*args, **kwargs) -> Union[Input, Output]:
return func(*args, **kwargs)
Expand All @@ -56,6 +57,7 @@ def wrapper(*args, **kwargs) -> Union[Input, Output]:
] = {
"usage": usage,
"description": description,
"content": content or func.__doc__,
"epilog": epilog,
}
return wrapper
Expand All @@ -70,8 +72,9 @@ def handler(
namespace: Optional[str] = None,
usage: Optional[str] = None,
description: Optional[str] = None,
content: Optional[str] = None,
epilog: Optional[str] = None,
sub_cmd: Optional[Dict[str, str]] = None,
sub_cmd: Optional[Dict[str, Annotation]] = None,
):
"""注册一个业务函数"""

Expand All @@ -91,6 +94,7 @@ def wrapper(*args, **kwargs) -> Output:
self.doc.handlers[namespace or _router.namespace or func.__name__] = {
"usage": usage,
"description": description,
"content": content or func.__doc__,
"epilog": epilog,
"sub_cmd": sub_cmd or {},
}
Expand All @@ -104,12 +108,14 @@ def register_textevent(
text: str,
*,
description: Optional[str] = None,
content: Optional[str] = None,
var_doc: Optional[Dict[str, str]] = None,
):
"""注册一个文本事件"""
self.events[name] = text
self.doc.events[name] = {
"description": description,
"content": content,
"var_doc": var_doc or {},
}

Expand All @@ -120,12 +126,14 @@ def register_variable(
*,
usage: Optional[str] = None,
description: Optional[str] = None,
content: Optional[str] = None,
):
"""注册一个静态全局变量"""
self.global_variables[name] = data
self.doc.global_variables[name] = {
"usage": usage,
"description": description,
"content": content,
}

def dynamic_variable(
Expand All @@ -134,6 +142,7 @@ def dynamic_variable(
*,
usage: Optional[str] = None,
description: Optional[str] = None,
content: Optional[str] = None,
):
"""注册一个动态全局变量"""

Expand All @@ -146,6 +155,7 @@ def wrapper(*args, **kwargs) -> str:
self.doc.global_variables[name or func.__name__] = {
"usage": usage,
"description": description,
"content": content or func.__doc__,
}
return wrapper

Expand All @@ -159,6 +169,7 @@ def interceptor(
namespace: Optional[str] = None,
usage: Optional[str] = None,
description: Optional[str] = None,
content: Optional[str] = None,
epilog: Optional[str] = None,
):
"""注册一个产出文本拦截器"""
Expand All @@ -179,6 +190,7 @@ def wrapper(*args, **kwargs) -> Union[Input, Output]:
self.doc.interceptors[namespace or _router.namespace or func.__name__] = {
"usage": usage,
"description": description,
"content": content or func.__doc__,
"epilog": epilog,
}
return wrapper
Expand Down

0 comments on commit b1f1500

Please sign in to comment.