11"""Command-line interface for litestar-start."""
22
3- import sys
43from pathlib import Path
54
65import questionary
@@ -28,6 +27,9 @@ def ask_project_name() -> str:
2827 Returns:
2928 The validated project name.
3029
30+ Raises:
31+ SystemExit: If the user cancels the operation.
32+
3133 """
3234 while True :
3335 name = questionary .text (
@@ -37,7 +39,7 @@ def ask_project_name() -> str:
3739
3840 if name is None : # User pressed Ctrl+C
3941 console .print ("\n [yellow]Cancelled.[/yellow]" )
40- sys . exit (0 )
42+ raise SystemExit (0 )
4143
4244 error = validate_project_name (name )
4345 if error :
@@ -53,6 +55,9 @@ def ask_framework() -> Framework:
5355 Returns:
5456 The selected framework.
5557
58+ Raises:
59+ SystemExit: If the user cancels the operation.
60+
5661 """
5762 choices = [
5863 questionary .Choice (title = "Litestar" , value = Framework .LITESTAR ),
@@ -65,7 +70,7 @@ def ask_framework() -> Framework:
6570
6671 if result is None :
6772 console .print ("\n [yellow]Cancelled.[/yellow]" )
68- sys . exit (0 )
73+ raise SystemExit (0 )
6974
7075 return result
7176
@@ -76,6 +81,9 @@ def ask_database() -> Database:
7681 Returns:
7782 The selected database.
7883
84+ Raises:
85+ SystemExit: If the user cancels the operation.
86+
7987 """
8088 choices = [
8189 questionary .Choice (title = "PostgreSQL" , value = Database .POSTGRESQL ),
@@ -91,7 +99,7 @@ def ask_database() -> Database:
9199
92100 if result is None :
93101 console .print ("\n [yellow]Cancelled.[/yellow]" )
94- sys . exit (0 )
102+ raise SystemExit (0 )
95103
96104 return result
97105
@@ -105,6 +113,9 @@ def ask_plugins(database: Database) -> list[Plugin]:
105113 Returns:
106114 A list of selected plugins.
107115
116+ Raises:
117+ SystemExit: If the user cancels the operation.
118+
108119 """
109120 choices = []
110121
@@ -127,7 +138,7 @@ def ask_plugins(database: Database) -> list[Plugin]:
127138
128139 if result is None :
129140 console .print ("\n [yellow]Cancelled.[/yellow]" )
130- sys . exit (0 )
141+ raise SystemExit (0 )
131142
132143 # Filter out None values
133144 return [p for p in result if p is not None ]
@@ -139,6 +150,9 @@ def ask_docker() -> tuple[bool, bool]:
139150 Returns:
140151 A tuple of (generate_dockerfile, generate_docker_infra).
141152
153+ Raises:
154+ SystemExit: If the user cancels the operation (e.g., presses Ctrl+C).
155+
142156 """
143157 docker = questionary .confirm (
144158 "Generate Dockerfile for the application?" ,
@@ -147,7 +161,7 @@ def ask_docker() -> tuple[bool, bool]:
147161
148162 if docker is None :
149163 console .print ("\n [yellow]Cancelled.[/yellow]" )
150- sys . exit (0 )
164+ raise SystemExit (0 )
151165
152166 docker_infra = questionary .confirm (
153167 "Generate docker-compose.infra.yml for local development (database, etc.)?" ,
@@ -156,13 +170,18 @@ def ask_docker() -> tuple[bool, bool]:
156170
157171 if docker_infra is None :
158172 console .print ("\n [yellow]Cancelled.[/yellow]" )
159- sys . exit (0 )
173+ raise SystemExit (0 )
160174
161175 return docker , docker_infra
162176
163177
164178def main () -> None :
165- """Run the main CLI interface."""
179+ """Run the main CLI interface.
180+
181+ Raises:
182+ SystemExit: If the user cancels the operation (e.g., presses Ctrl+C).
183+
184+ """
166185 print_banner ()
167186
168187 try :
@@ -202,7 +221,7 @@ def main() -> None:
202221 proceed = questionary .confirm ("Generate project?" , default = True ).ask ()
203222 if not proceed :
204223 console .print ("[yellow]Cancelled.[/yellow]" )
205- sys . exit (0 )
224+ raise SystemExit (0 )
206225
207226 # Generate project
208227 output_dir = Path .cwd () / config .slug
@@ -224,7 +243,7 @@ def main() -> None:
224243
225244 except KeyboardInterrupt :
226245 console .print ("\n [yellow]Cancelled.[/yellow]" )
227- sys . exit ( 0 )
246+ return
228247
229248
230249if __name__ == "__main__" :
0 commit comments