Created
May 4, 2023 17:38
-
-
Save daaniam/4873f05470de917ab1d6a45993697c87 to your computer and use it in GitHub Desktop.
Async typer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AsyncTyper(typer.Typer): | |
def __init__(self, *args, **kwargs): | |
kwargs["no_args_is_help"] = True | |
super().__init__(*args, **kwargs) | |
def async_command(self, *args, **kwargs): | |
def decorator(async_func): | |
@wraps(async_func) | |
def sync_func(*_args, **_kwargs): | |
return run(async_func(*_args, **_kwargs)) | |
self.command(*args, **kwargs)(sync_func) | |
return async_func | |
return decorator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment