Skip to content

Commit 851591d

Browse files
committed
update the cloner directory
1 parent 5da80ae commit 851591d

File tree

6 files changed

+147
-209
lines changed

6 files changed

+147
-209
lines changed
Lines changed: 30 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import re
55
import time
66
from typing import Optional
7-
from rich import print
87

98
import typer
9+
from rich import print
1010

1111
from fastapi_ccli import GREEN, RED, github_fs_src, gitee_fs_src, github_ft_src, gitee_ft_src
1212
from fastapi_ccli.utils.get_country import get_current_country
@@ -19,7 +19,7 @@
1919

2020
def orm_callback(orm: str) -> str:
2121
"""
22-
Which to use orm
22+
Select the orm to use...
2323
2424
:param orm:
2525
:return:
@@ -31,15 +31,16 @@ def orm_callback(orm: str) -> str:
3131
use_orm = typer.style('tortoise-orm', fg='green', bold=True)
3232
else:
3333
raise typer.BadParameter(
34-
"Enter unknown parameters, only allowed 'sqlalchemy' / 's' or 'tortoise-orm' / 't'")
34+
"Enter unknown parameters, only allowed 'sqlalchemy' / 's' or 'tortoise-orm' / 't'."
35+
)
3536
else:
3637
use_orm = typer.style('sqlalchemy', fg='green', bold=True)
3738
return use_orm
3839

3940

4041
def project_path_callback(project_path: str) -> str:
4142
"""
42-
Custom project path...
43+
Select project path...
4344
4445
:param project_path:
4546
:return:
@@ -68,62 +69,53 @@ def is_dns() -> str:
6869
continue
6970
rp = get_current_country(ip)
7071
if 'CN' in rp:
71-
if dns:
72-
ending = GREEN
73-
else:
74-
ending = RED
72+
ending = GREEN if dns else RED
7573
else:
76-
if dns:
77-
ending = RED
78-
else:
79-
ending = GREEN
74+
ending = RED if dns else GREEN
8075
return ending
8176

8277

8378
def is_async_app() -> str:
8479
async_app = typer.confirm('Do you want to use async?', default=True)
85-
if async_app:
86-
ending = GREEN
87-
else:
88-
ending = RED
80+
ending = GREEN if async_app else RED
8981
return ending
9082

9183

9284
def is_generic_crud() -> str:
9385
generic_crud = typer.confirm('Do you want to use generic crud?', default=True)
94-
if generic_crud:
95-
ending = GREEN
96-
else:
97-
ending = RED
86+
ending = GREEN if generic_crud else RED
9887
return ending
9988

10089

10190
def is_casbin() -> str:
10291
casbin = typer.confirm('Do you want to use rbac?', default=True)
103-
if casbin:
104-
ending = GREEN
105-
else:
106-
ending = RED
92+
ending = GREEN if casbin else RED
10793
return ending
10894

10995

11096
@app_en.command(epilog="Made by :beating_heart: wu-clan")
11197
def cloner(
98+
_version: Optional[bool] = typer.Option(
99+
None,
100+
"--version",
101+
'-V',
102+
help="Print version information and quit"
103+
),
112104
orm: Optional[str] = typer.Option(
113105
None,
114106
"--orm",
115107
"-o",
116108
callback=orm_callback,
117-
help="Select the orm to use, the default is sqlalchemy, support sqlalchemy or tortoise-orm, "
118-
"you can also use the shorthand, s or t."
109+
help="Select the orm to use, the default is sqlalchemy, support 'sqlalchemy' or 'tortoise-orm', "
110+
"you can also use the shorthand, 's' or 't'."
119111
),
120112
project_path: Optional[str] = typer.Option(
121113
None,
122114
"--path",
123115
"-p",
124116
callback=project_path_callback,
125-
help="Project clone path, the default is ../fastapi_project, supports absolute path or relative path, "
126-
"for example, Absolute path: D:\\fastapi project, relative path: ../fastapi_project."
117+
help="Project clone path, the default is '../fastapi_project', supports absolute path or relative path, "
118+
"E.g., Absolute path: D:\\fastapi_project, relative path: ../fastapi_project."
127119
),
128120
):
129121
"""
@@ -143,33 +135,23 @@ def cloner(
143135
typer.echo('Select orm: ' + orm)
144136
typer.echo('Use dns: ' + dns)
145137
typer.echo('Use async: ' + async_app)
146-
typer.echo('Use generics crud: ' + generic_crud)
138+
typer.echo('Use generic crud: ' + generic_crud)
147139
if casbin:
148140
typer.echo('Use rbac: ' + casbin)
149-
if 'True' in dns:
150-
src = get_sqlalchemy_app_src(
151-
src=github_fs_src,
152-
async_app=async_app,
153-
generic_crud=generic_crud,
154-
casbin=casbin
155-
)
156-
else:
157-
src = get_sqlalchemy_app_src(
158-
src=gitee_fs_src,
159-
async_app=async_app,
160-
generic_crud=generic_crud,
161-
casbin=casbin
162-
)
141+
source = github_fs_src if 'True' in dns else gitee_fs_src
142+
src = get_sqlalchemy_app_src(
143+
src=source,
144+
async_app=async_app,
145+
generic_crud=generic_crud,
146+
casbin=casbin
147+
)
163148
__exec_clone(orm, src, path, path_style)
164149
else:
165150
dns = is_dns()
166151
typer.echo('Project name: ' + typer.style(project_name, fg='blue', bold=True))
167-
typer.echo('Select orm: ' + orm)
152+
typer.echo('Use orm: ' + orm)
168153
typer.echo('Use dns: ' + dns)
169-
if 'True' in dns:
170-
src = github_ft_src
171-
else:
172-
src = gitee_ft_src
154+
src = github_ft_src if 'True' in dns else gitee_ft_src
173155
__exec_clone(orm, src, path, path_style)
174156

175157

@@ -182,7 +164,6 @@ def __exec_clone(orm: str, src: str, path: str, path_style: str) -> None:
182164
:return:
183165
"""
184166
try:
185-
# typer.launch(src)
186167
if 'sqlalchemy' in orm:
187168
print(f'⏳ Start cloning branch {src.split()[0]} of repository {src.split()[1]}')
188169
out = os.system(f'git clone -b {src} {path}')
@@ -197,4 +178,3 @@ def __exec_clone(orm: str, src: str, path: str, path_style: str) -> None:
197178
else:
198179
print('✅ The project was cloned successfully')
199180
typer.echo(f'Please go to the directory {path_style} to view')
200-
raise typer.Abort()
Lines changed: 43 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
import re
55
import time
66
from typing import Optional
7-
from rich import print
87

98
import questionary
109
import typer
10+
from rich import print
1111

1212
from fastapi_ccli import GREEN, RED, github_fs_src, gitee_fs_src, github_ft_src, gitee_ft_src
1313
from fastapi_ccli.utils.get_country import get_current_country
@@ -20,7 +20,7 @@
2020

2121
def project_path_callback(project_path: str) -> str:
2222
"""
23-
Custom project path
23+
Select project path...
2424
2525
:param project_path:
2626
:return:
@@ -37,7 +37,7 @@ def project_path_callback(project_path: str) -> str:
3737

3838
def orm_style(orm: str) -> str:
3939
"""
40-
orm stylization
40+
orm stylization...
4141
4242
:param orm:
4343
:return:
@@ -47,7 +47,7 @@ def orm_style(orm: str) -> str:
4747

4848
def is_dns(dns: bool) -> str:
4949
"""
50-
Whether to use dns
50+
Whether to use dns...
5151
5252
:param dns:
5353
:return:
@@ -64,69 +64,60 @@ def is_dns(dns: bool) -> str:
6464
continue
6565
rp = get_current_country(ip)
6666
if 'CN' in rp:
67-
if 'Yes' in dns:
68-
ending = GREEN
69-
else:
70-
ending = RED
67+
ending = GREEN if 'Yes' in dns else RED
7168
else:
72-
if 'Yes' in dns:
73-
ending = RED
74-
else:
75-
ending = GREEN
69+
ending = RED if 'Yes' in dns else GREEN
7670
return ending
7771

7872

7973
def is_async_app(async_app: bool) -> str:
8074
"""
81-
Whether to use async
75+
Whether to use async...
8276
8377
:param async_app:
8478
:return:
8579
"""
86-
if 'Yes' in async_app:
87-
ending = GREEN
88-
else:
89-
ending = RED
80+
ending = GREEN if 'Yes' in async_app else RED
9081
return ending
9182

9283

9384
def is_generic_crud(generic_crud: bool) -> str:
9485
"""
95-
Whether to use generic crud
86+
Whether to use generic crud...
9687
9788
:param generic_crud:
9889
:return:
9990
"""
100-
if 'Yes' in generic_crud:
101-
ending = GREEN
102-
else:
103-
ending = RED
91+
ending = GREEN if 'Yes' in generic_crud else RED
10492
return ending
10593

10694

10795
def is_casbin(casbin: bool) -> str:
10896
"""
109-
Whether to use rbac
97+
Whether to use rbac...
11098
11199
:param casbin:
112100
:return:
113101
"""
114-
if 'Yes' in casbin:
115-
ending = GREEN
116-
else:
117-
ending = RED
102+
ending = GREEN if 'Yes' in casbin else RED
118103
return ending
119104

120105

121106
@app_en_form.command(epilog="Made by :beating_heart: wu-clan")
122107
def cloner(
108+
_version: Optional[bool] = typer.Option(
109+
None,
110+
"--version",
111+
'-V',
112+
help="Print version information and quit"
113+
),
123114
project_path: Optional[str] = typer.Option(
124115
None,
125116
"--path",
126117
"-p",
127118
callback=project_path_callback,
128-
help="Project clone path, the default is ../fastapi_project, supports absolute path or relative path, "
129-
"for example, Absolute path: D:\\fastapi project, relative path: ../fastapi_project."
119+
help="Project clone path, the default is '../fastapi_project', supports absolute path or relative path, "
120+
"E.g., Absolute path: D:\\fastapi_project, relative path: ../fastapi_project."
130121
),
131122
):
132123
"""
@@ -139,50 +130,49 @@ def cloner(
139130
orm=questionary.select('Please select the orm you want to use:', choices=['SQLAlchemy', 'Tortoise-ORM'],
140131
default='SQLAlchemy'),
141132
dns=questionary.select('Do you want to use dns?', choices=['Yes', 'No'], default='No'),
142-
).unsafe_ask()
133+
).ask()
134+
if len(result_if) == 0:
135+
raise typer.Abort
143136
dns = is_dns(result_if['dns'])
144137
orm = orm_style(result_if['orm'])
145138
if 'SQLAlchemy' in orm:
146139
result = questionary.form(
147140
async_app=questionary.select('Do you want to use async?', choices=['Yes', 'No']),
148141
generic_crud=questionary.select('Do you want to use generic crud?', choices=['Yes', 'No']),
149-
casbin=questionary.select('Do you want to use rbac?', choices=['Yes', 'No']),
150-
).unsafe_ask()
142+
).ask()
143+
if len(result) == 0:
144+
raise typer.Abort
151145
async_app = is_async_app(result['async_app'])
152146
generic_crud = is_generic_crud(result['generic_crud'])
153147
casbin = None
154148
if 'True' in generic_crud:
155-
casbin = is_casbin(result['casbin'])
149+
rbac = questionary.form(
150+
casbin=questionary.select('Do you want to use rbac authentication?', choices=['Yes', 'No'])
151+
).ask()
152+
if len(rbac) == 0:
153+
raise typer.Abort
154+
if rbac['casbin'] == 'Yes':
155+
casbin = is_casbin(rbac['casbin'])
156156
typer.echo('Project name:' + project_name)
157157
typer.echo('Use orm:' + orm)
158158
typer.echo('Use dns:' + dns)
159159
typer.echo('Use async:' + async_app)
160-
typer.echo('Use generics crud:' + generic_crud)
160+
typer.echo('Use generic crud:' + generic_crud)
161161
if casbin:
162-
typer.echo('Use rbac:' + casbin)
163-
if 'True' in dns:
164-
src = get_sqlalchemy_app_src(
165-
src=github_fs_src,
166-
async_app=async_app,
167-
generic_crud=generic_crud,
168-
casbin=casbin
169-
)
170-
else:
171-
src = get_sqlalchemy_app_src(
172-
src=gitee_fs_src,
173-
async_app=async_app,
174-
generic_crud=generic_crud,
175-
casbin=casbin
176-
)
162+
typer.echo('Use rbac authentication:' + casbin)
163+
source = github_fs_src if 'True' in dns else gitee_fs_src
164+
src = get_sqlalchemy_app_src(
165+
src=source,
166+
async_app=async_app,
167+
generic_crud=generic_crud,
168+
casbin=casbin
169+
)
177170
__exec_clone(orm, src, path, path_style)
178171
else:
179172
typer.echo('Project name:' + project_name)
180173
typer.echo('Use orm:' + orm)
181174
typer.echo('Use dns:' + dns)
182-
if 'True' in dns:
183-
src = github_ft_src
184-
else:
185-
src = gitee_ft_src
175+
src = github_ft_src if 'True' in dns else gitee_ft_src
186176
__exec_clone(orm, src, path, path_style)
187177

188178

@@ -211,4 +201,3 @@ def __exec_clone(orm: str, src: str, path: str, path_style: str) -> None:
211201
else:
212202
print('✅ The repository was cloned successfully')
213203
typer.echo(f'Please go to the directory {path_style} to view')
214-
raise typer.Abort()

fastapi_ccli/cloner/zh/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-

0 commit comments

Comments
 (0)