Skip to content

Commit b969432

Browse files
committed
Added default async command support for AppContextGroup
1 parent f372e4b commit b969432

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

ellar_cli/click/group.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import inspect
12
import typing as t
23

34
import click
45
from ellar.app import AppFactory
56
from ellar.common.constants import MODULE_METADATA
67
from ellar.core import ModuleBase, ModuleSetup, reflector
8+
from ellar.threading import run_as_sync
79

810
from ellar_cli.constants import ELLAR_META
911
from ellar_cli.service import EllarCLIService, EllarCLIServiceWithPyProject
@@ -30,6 +32,9 @@ def command( # type:ignore[override]
3032
wrap_for_ctx = kwargs.pop("with_injector_context", True)
3133

3234
def decorator(f: t.Callable) -> t.Any:
35+
if inspect.iscoroutinefunction(f):
36+
f = run_as_sync(f)
37+
3338
if wrap_for_ctx:
3439
f = with_injector_context(f)
3540
return super(AppContextGroup, self).command(*args, **kwargs)(f)

ellar_cli/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def version_callback(ctx: click.Context, _: t.Any, value: bool) -> None:
2525
raise click.Exit(0)
2626

2727

28-
def create_ellar_cli(app_import_string: t.Optional[str] = None) -> click.Group:
28+
def create_ellar_cli(app_import_string: t.Optional[str] = None) -> EllarCommandGroup:
2929
@click.group(
3030
name="Ellar CLI Tool... ",
3131
cls=EllarCommandGroup,

ellar_cli/service/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def _import_and_validate_application(
179179
)
180180

181181
if is_callable:
182-
app = app() # type:ignore[call-arg]
182+
app = app()
183183

184184
if not isinstance(app, App):
185185
raise EllarCLIException(

0 commit comments

Comments
 (0)