Skip to content

Commit 1340db9

Browse files
♻️ Simplify code in src/fastapi_cli/discover.py (#22)
1 parent d9748a2 commit 1340db9

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

src/fastapi_cli/discover.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,20 @@
2222

2323

2424
def get_default_path() -> Path:
25-
path = Path("main.py")
26-
if path.is_file():
27-
return path
28-
path = Path("app.py")
29-
if path.is_file():
30-
return path
31-
path = Path("api.py")
32-
if path.is_file():
33-
return path
34-
path = Path("app/main.py")
35-
if path.is_file():
36-
return path
37-
path = Path("app/app.py")
38-
if path.is_file():
39-
return path
40-
path = Path("app/api.py")
41-
if path.is_file():
42-
return path
25+
potential_paths = (
26+
"main.py",
27+
"app.py",
28+
"api.py",
29+
"app/main.py",
30+
"app/app.py",
31+
"app/api.py",
32+
)
33+
34+
for full_path in potential_paths:
35+
path = Path(full_path)
36+
if path.is_file():
37+
return path
38+
4339
raise FastAPICLIException(
4440
"Could not find a default file to run, please provide an explicit path"
4541
)

0 commit comments

Comments
 (0)