11import os
2+ import secrets
23import typing as t
3- import uuid
44from importlib import import_module
5+ from pathlib import Path
56
67import typer
78from ellar .common .helper .module_loading import module_dir
2223
2324
2425class ProjectTemplateScaffold (FileTemplateScaffold ):
25- def __init__ (self , ellar_cli_service : EllarCLIService , ** kwargs : t .Any ) -> None :
26- super ().__init__ (** kwargs )
26+ def __init__ (
27+ self ,
28+ ellar_cli_service : EllarCLIService ,
29+ working_project_name : str ,
30+ working_directory : str ,
31+ ** kwargs : t .Any ,
32+ ) -> None :
33+ super ().__init__ (
34+ ** kwargs ,
35+ working_project_name = working_project_name ,
36+ working_directory = working_directory ,
37+ )
2738 self .ellar_cli_service = ellar_cli_service
39+ self ._working_project_name = working_project_name
40+ if self ._specified_directory :
41+ _cwd_path = Path (self ._get_working_cwd (working_directory ))
42+ self ._working_directory = str (_cwd_path )
43+ else :
44+ self ._working_directory = working_directory
45+
46+ self .prefix : t .Optional [str ] = None
47+ if self ._specified_directory and "." not in self ._specified_directory :
48+ self .prefix = self ._specified_directory .replace ("/" , "." ).lower ()
49+
50+ if self .prefix .startswith ("." ): # pragma: no cover
51+ self .prefix = self .prefix [1 :]
52+
53+ if self .prefix .endswith ("." ): # pragma: no cover
54+ self .prefix = self .prefix [:- 1 ]
2855
2956 def get_scaffolding_context (self , working_project_name : str ) -> t .Dict :
57+ _prefix = f"{ self .prefix } ." if self .prefix else ""
3058 template_context = {
3159 "project_name" : working_project_name ,
32- "secret_key" : f"ellar_{ uuid .uuid4 ()} " ,
60+ "secret_key" : f"ellar_{ secrets .token_hex (32 )} " ,
61+ "config_prefix" : _prefix ,
3362 }
3463 return template_context
3564
@@ -60,8 +89,10 @@ def validate_project_name(self) -> None:
6089 raise EllarCLIException (message )
6190
6291 def on_scaffold_completed (self ) -> None :
92+ _working_project_name = self ._working_project_name
93+
6394 self .ellar_cli_service .create_ellar_project_meta (
64- project_name = self ._working_project_name
95+ project_name = _working_project_name , prefix = self .prefix
6596 )
6697 print (
6798 f"`{ self ._working_project_name } ` project scaffold completed. To start your server, run the command below"
@@ -70,7 +101,15 @@ def on_scaffold_completed(self) -> None:
70101 print ("Happy coding!" )
71102
72103
73- def create_project (ctx : typer .Context , project_name : str ):
104+ def create_project (
105+ ctx : typer .Context ,
106+ project_name : str ,
107+ directory : t .Optional [str ] = typer .Argument (
108+ None ,
109+ help = "The name of a new directory to scaffold the project into." ,
110+ show_default = False ,
111+ ),
112+ ):
74113 """- Scaffolds Ellar Application -"""
75114
76115 ellar_project_meta = t .cast (t .Optional [EllarCLIService ], ctx .meta .get (ELLAR_META ))
@@ -86,6 +125,7 @@ def create_project(ctx: typer.Context, project_name: str):
86125 working_directory = os .getcwd (),
87126 scaffold_ellar_template_root_path = root_scaffold_template_path ,
88127 ellar_cli_service = ellar_project_meta ,
128+ specified_directory = directory ,
89129 working_project_name = project_name .lower (),
90130 )
91131 project_template_scaffold .scaffold ()
0 commit comments