diff --git a/src/atsphinx/helpers/decorators.py b/src/atsphinx/helpers/decorators.py index 27808e8..edb125c 100644 --- a/src/atsphinx/helpers/decorators.py +++ b/src/atsphinx/helpers/decorators.py @@ -69,6 +69,7 @@ def emit_only( builders: Optional[List[str]] = None, formats: Optional[List[str]] = None, loglevel: int = logging.INFO, + return_alt: Any = None, ): """Restict event handler workings by builder types or formats. @@ -91,6 +92,7 @@ def setup(app): :params builders: List of builder names for restrict target. :params formats: List of format types for restrict target. + :params return_alt: Return value if guard is worked. """ if builders is None and formats is None: Logger.log( @@ -108,13 +110,13 @@ def __only(app: Sphinx, *args, **kwargs) -> Any: loglevel, f"{func.__name__} is not supported '{app.builder.name}' builder.", ) - return + return return_alt if formats and app.builder.format not in formats: logger.log( loglevel, f"{func.__name__} is not supported '{app.builder.format}' format.", ) - return + return return_alt return func(app, *args, **kwargs) return __only