|
2 | 2 | import sys |
3 | 3 | import typing as t |
4 | 4 | from importlib import import_module |
| 5 | +from pathlib import Path |
5 | 6 |
|
6 | 7 | import typer |
7 | 8 | from ellar.common.helper.module_loading import module_dir |
8 | 9 |
|
9 | 10 | from ellar_cli import scaffolding |
10 | | -from ellar_cli.constants import ELLAR_META |
11 | 11 | from ellar_cli.schema import EllarScaffoldSchema |
12 | 12 |
|
13 | 13 | from ..file_scaffolding import FileTemplateScaffold |
14 | | -from ..service import EllarCLIException, EllarCLIService |
| 14 | +from ..service import EllarCLIException |
15 | 15 |
|
16 | 16 | __all__ = ["create_module"] |
17 | 17 |
|
|
21 | 21 |
|
22 | 22 |
|
23 | 23 | class ModuleTemplateScaffold(FileTemplateScaffold): |
| 24 | + def __init__( |
| 25 | + self, working_project_name: str, working_directory: str, **kwargs: t.Any |
| 26 | + ) -> None: |
| 27 | + super().__init__( |
| 28 | + working_project_name=working_project_name, |
| 29 | + working_directory=working_directory, |
| 30 | + **kwargs, |
| 31 | + ) |
| 32 | + if self._specified_directory: |
| 33 | + _cwd_path = Path(self._get_working_cwd(working_directory)) |
| 34 | + self._working_project_name = working_project_name |
| 35 | + self._working_directory = str(_cwd_path) |
| 36 | + |
24 | 37 | def on_scaffold_completed(self) -> None: |
25 | 38 | print(f"{self._working_project_name} module completely scaffolded") |
26 | 39 |
|
@@ -59,24 +72,22 @@ def get_scaffolding_context(self, working_project_name: str) -> t.Dict: |
59 | 72 | return template_context |
60 | 73 |
|
61 | 74 |
|
62 | | -def create_module(ctx: typer.Context, module_name: str): |
| 75 | +def create_module( |
| 76 | + module_name: str, |
| 77 | + directory: t.Optional[str] = typer.Argument( |
| 78 | + None, |
| 79 | + help="The name of a new directory to scaffold the module into.", |
| 80 | + show_default=False, |
| 81 | + ), |
| 82 | +): |
63 | 83 | """- Scaffolds Ellar Application Module -""" |
64 | 84 |
|
65 | | - ellar_project_meta = t.cast(t.Optional[EllarCLIService], ctx.meta.get(ELLAR_META)) |
66 | | - if not ellar_project_meta: |
67 | | - raise EllarCLIException("No pyproject.toml file found.") |
68 | | - |
69 | | - if not ellar_project_meta.has_meta: |
70 | | - raise EllarCLIException( |
71 | | - "No available project found. please create ellar project with `ellar create-project 'project-name'`" |
72 | | - ) |
73 | | - |
74 | 85 | schema = EllarScaffoldSchema.parse_file(module_template_json) |
75 | 86 | project_template_scaffold = ModuleTemplateScaffold( |
76 | 87 | schema=schema, |
77 | | - working_directory=ellar_project_meta.get_apps_module_path(), |
| 88 | + working_directory=os.getcwd(), |
78 | 89 | scaffold_ellar_template_root_path=root_scaffold_template_path, |
79 | | - ellar_cli_service=ellar_project_meta, |
| 90 | + specified_directory=directory, |
80 | 91 | working_project_name=module_name.lower(), |
81 | 92 | ) |
82 | 93 | project_template_scaffold.scaffold() |
0 commit comments