99from ellar_cli .service import EllarCLIService , EllarCLIServiceWithPyProject
1010
1111from .command import Command
12- from .util import with_app_context
12+ from .util import with_injector_context
1313
1414
1515class AppContextGroup (click .Group ):
1616 """This works similar to a regular click.Group, but it
1717 changes the behavior of the command decorator so that it
18- automatically wraps the functions in `pass_with_app_context `.
18+ automatically wraps the functions in `with_injector_context `.
1919 """
2020
2121 command_class = Command
2222
23- def command (self , * args : t .Any , ** kwargs : t .Any ) -> t .Callable : # type:ignore[override]
23+ def command ( # type:ignore[override]
24+ self , * args : t .Any , ** kwargs : t .Any
25+ ) -> t .Union [t .Callable [[t .Callable [..., t .Any ]], click .Command ], click .Command ]:
2426 """The same with click.Group command.
25- It only decorates the command function to be run under `applicationContext `.
26- It's disabled by passing `with_app_context =False`.
27+ It only decorates the command function to be run under `ellar.core.with_injector_context `.
28+ It's disabled by passing `with_injector_context =False`.
2729 """
28- wrap_for_ctx = kwargs .pop ("with_app_context " , True )
30+ wrap_for_ctx = kwargs .pop ("with_injector_context " , True )
2931
3032 def decorator (f : t .Callable ) -> t .Any :
3133 if wrap_for_ctx :
32- f = with_app_context (f )
33- return click . Group . command ( self , * args , ** kwargs )(f )
34+ f = with_injector_context (f )
35+ return super ( AppContextGroup , self ). command ( * args , ** kwargs )(f )
3436
3537 return decorator
3638
37- def group (self , * args : t .Any , ** kwargs : t .Any ) -> t .Any :
39+ def group ( # type:ignore[override]
40+ self , * args : t .Any , ** kwargs : t .Any
41+ ) -> t .Union [t .Callable [[t .Callable [..., t .Any ]], click .Group ], click .Group ]:
3842 """This works exactly like the method of the same name on a regular click.Group but it defaults
3943 the group class to `AppGroup`.
4044 """
41- kwargs .setdefault ("cls" , AppContextGroup )
42- return click . Group . group ( self , * args , ** kwargs )
45+ kwargs .setdefault ("cls" , self . __class__ )
46+ return super ( AppContextGroup , self ). group ( * args , ** kwargs ) # type:ignore[no-any-return]
4347
4448
4549class EllarCommandGroup (AppContextGroup ):
@@ -62,7 +66,9 @@ def _load_application_commands(self, ctx: click.Context) -> None:
6266 if self ._cli_meta :
6367 application = self ._cli_meta .import_application ()
6468
65- module_configs = (i for i in application .injector .get_modules ().keys ())
69+ module_configs = (
70+ i for i in application .injector .tree_manager .modules .keys ()
71+ )
6672
6773 ctx .meta [ELLAR_META ] = self ._cli_meta
6874 else :
@@ -77,12 +83,10 @@ def _load_application_commands(self, ctx: click.Context) -> None:
7783 ctx .meta [ELLAR_META ] = meta_
7884
7985 if meta_ and meta_ .has_meta :
80- module_configs = (
81- module_config .module
82- for module_config in AppFactory .get_all_modules (
83- ModuleSetup (meta_ .import_root_module ())
84- )
86+ tree_manager = AppFactory .read_all_module (
87+ ModuleSetup (meta_ .import_root_module ())
8588 )
89+ module_configs = tree_manager .modules .keys ()
8690 self ._find_commands_from_modules (module_configs )
8791
8892 def _find_commands_from_modules (
0 commit comments