Skip to content

Commit

Permalink
feat: check formater class
Browse files Browse the repository at this point in the history
  • Loading branch information
JinnLynn committed Jun 12, 2024
1 parent ca2e199 commit d9ee592
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/genpac/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def __init__(self, config_file=None, argv_enabled=True):
@classmethod
def add_formater(cls, name, fmt_cls, **options):
fmt_cls._name = name.lower()
if fmt_cls._name in cls._formaters:
raise RuntimeError(f'输出格式{fmt_cls._name}重复')
fmt_cls._desc = options.pop('desc', None)
cls._formaters[name] = {'cls': fmt_cls,
'options': options}
Expand Down
2 changes: 2 additions & 0 deletions src/genpac/format/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
# decorator: 添加格式化器
def formater(name, **options):
def decorator(fmt_cls):
if not issubclass(fmt_cls, FmtBase):
raise RuntimeError(f'格式类错误,必须继承自FmtBase: {fmt_cls}')
GenPAC.add_formater(name, fmt_cls, **options)
return fmt_cls
return decorator
Expand Down

0 comments on commit d9ee592

Please sign in to comment.