33import os
44import re
55import time
6+
67from pathlib import Path
78from typing import Optional
89
910import typer
11+
1012from rich import print
1113
1214from fastapi_ccli import __version__
13- from fastapi_ccli .cloner import GREEN , RED , github_fba_src , github_ftm_src , github_fsm_src , gitee_fba_src , gitee_ftm_src
15+ from fastapi_ccli .cloner import GREEN , RED , gitee_fba_src , gitee_ftm_src , github_fba_src , github_fsm_src , github_ftm_src
1416from fastapi_ccli .utils .get_country import get_current_country
1517from fastapi_ccli .utils .get_ip import get_net_ip
1618from fastapi_ccli .utils .get_path import get_project_path
1719
18- app_en = typer .Typer (rich_markup_mode = " rich" )
20+ app_en = typer .Typer (rich_markup_mode = ' rich' )
1921
2022
2123def is_china (dns : bool ) -> str :
@@ -25,7 +27,7 @@ def is_china(dns: bool) -> str:
2527 :param dns:
2628 :return:
2729 """
28- with typer .progressbar (range (5 ), label = " Analyzing" ) as progress :
30+ with typer .progressbar (range (5 ), label = ' Analyzing' ) as progress :
2931 for i in progress :
3032 ip = get_net_ip ()
3133 if ip :
@@ -36,7 +38,7 @@ def is_china(dns: bool) -> str:
3638 progress .update (i )
3739 continue
3840 rp = get_current_country (ip )
39- if "CN" in rp :
41+ if 'CN' in rp :
4042 ending = GREEN if dns else RED
4143 else :
4244 ending = RED if dns else GREEN
@@ -53,47 +55,47 @@ def exec_clone(orm: str, country: str, project: str, path: str) -> None:
5355 :param path:
5456 :return:
5557 """
56- typer .echo (" Project name: " + typer .style (project , fg = " blue" , bold = True ))
57- typer .echo (" Select orm: " + orm )
58- if orm == " sqlalchemy" :
59- source = github_fba_src if " True" in country else gitee_fba_src
60- elif orm == " tortoise" :
61- source = github_ftm_src if " True" in country else gitee_ftm_src
62- elif orm == " sqlmodel" :
58+ typer .echo (' Project name: ' + typer .style (project , fg = ' blue' , bold = True ))
59+ typer .echo (' Select orm: ' + orm )
60+ if orm == ' sqlalchemy' :
61+ source = github_fba_src if ' True' in country else gitee_fba_src
62+ elif orm == ' tortoise' :
63+ source = github_ftm_src if ' True' in country else gitee_ftm_src
64+ elif orm == ' sqlmodel' :
6365 source = github_fsm_src
6466 try :
6567 print (f"⏳ Start clone { source .split ('/' )[- 1 ].split ('.' )[0 ]} project..." ) # noqa
66- out = os .system (f" git clone { source } { path } " )
68+ out = os .system (f' git clone { source } { path } ' )
6769 if out != 0 :
6870 raise RuntimeError (out )
6971 except Exception as e :
70- print (f" ❌ Clone project failed: { e } " )
72+ print (f' ❌ Clone project failed: { e } ' )
7173 raise typer .Exit (1 )
7274 else :
73- print (" ✅ The project was cloned successfully" )
75+ print (' ✅ The project was cloned successfully' )
7476 typer .echo (f"Please go to the directory { typer .style (path , fg = 'green' , bold = True )} to view" )
7577
7678
77- @app_en .command (epilog = " Made by :beating_heart: wu-clan" )
79+ @app_en .command (epilog = ' Made by :beating_heart: wu-clan' )
7880def cloner (
7981 version : Optional [bool ] = typer .Option (
8082 None ,
81- " --version" ,
82- "-V" ,
83- help = " Print version information." ,
83+ ' --version' ,
84+ '-V' ,
85+ help = ' Print version information.' ,
8486 ),
8587 orm : Optional [str ] = typer .Option (
86- " sqlalchemy" ,
87- " --orm" ,
88- "-o" ,
89- metavar = " <ORM>" ,
88+ ' sqlalchemy' ,
89+ ' --orm' ,
90+ '-o' ,
91+ metavar = ' <ORM>' ,
9092 help = "Select the orm to use, the default is sqlalchemy, support 'sqlalchemy' / 'tortoise' / 'sqlmodel'." ,
9193 ),
9294 project_path : Optional [str ] = typer .Option (
9395 None ,
94- " --path" ,
95- "-p" ,
96- metavar = " <PATH>" ,
96+ ' --path' ,
97+ '-p' ,
98+ metavar = ' <PATH>' ,
9799 show_default = False ,
98100 help = "Project clone path, the default is '../fastapi_project', supports absolute path or relative path." ,
99101 ),
@@ -102,16 +104,16 @@ def cloner(
102104 FastAPI project cloner
103105 """
104106 if version :
105- typer .secho (" \n 🔥 FastAPI CCLI " + __version__ , fg = " green" , bold = True )
107+ typer .secho (' \n 🔥 FastAPI CCLI ' + __version__ , fg = ' green' , bold = True )
106108 if orm :
107- if orm not in [" sqlalchemy" , " tortoise" , " sqlmodel" ]:
109+ if orm not in [' sqlalchemy' , ' tortoise' , ' sqlmodel' ]:
108110 raise typer .BadParameter ("Enter unknown parameters, only allowed 'sqlalchemy' / 'tortoise' / 'sqlmodel'" )
109111 if project_path :
110112 if not Path (project_path ).is_dir ():
111- raise typer .BadParameter (" Wrong parameter input, please enter the correct path" )
112- use_project_name = project_path or " ../fastapi_project"
113+ raise typer .BadParameter (' Wrong parameter input, please enter the correct path' )
114+ use_project_name = project_path or ' ../fastapi_project'
113115 path = get_project_path (use_project_name )
114- project_name = re .split (r" /|\'|\\|\\\\" , use_project_name )[- 1 ]
115- _country = typer .confirm (" Is your region China?" , default = False )
116+ project_name = re .split (r' /|\'|\\|\\\\' , use_project_name )[- 1 ]
117+ _country = typer .confirm (' Is your region China?' , default = False )
116118 country = is_china (_country )
117119 exec_clone (orm , country , project_name , path )
0 commit comments