33import click
44
55from fastapi_forge .frontend import init
6+ from fastapi_forge .project_io import ProjectLoader
67
78
89@click .group ()
@@ -14,44 +15,52 @@ def main() -> None:
1415@click .option (
1516 "--use-example" ,
1617 is_flag = True ,
17- help = "Generate a new project using a prebuilt example provided by FastAPI Forge. "
18- "This option is ideal for quickly getting started with a standard template." ,
18+ help = "Generate a new project using a prebuilt example provided by FastAPI Forge." ,
1919)
2020@click .option (
2121 "--no-ui" ,
2222 is_flag = True ,
23- help = "Generate the project directly in the terminal without launching the UI. "
24- "Use this option for headless environments or when you prefer a CLI-only workflow." ,
23+ help = "Generate the project directly in the terminal without launching the UI." ,
2524)
2625@click .option (
2726 "--from-yaml" ,
2827 type = click .Path (exists = True , dir_okay = False , readable = True ),
29- help = "Generate a project using a custom configuration from a YAML file. "
30- "Provide the path to the YAML file (supports relative or absolute paths, and '~' for home directory). "
31- "Use '--no-ui' to generate the project immediately, otherwise the configuration will be loaded into the UI for further customization." ,
28+ help = "Generate a project using a custom configuration from a YAML file." ,
3229)
33- def start (use_example : bool , no_ui : bool , from_yaml : str | None = None ) -> None :
30+ @click .option (
31+ "--db-url" ,
32+ help = "PostgreSQL connection URL (e.g., postgresql://user:password@host:port/dbname)" ,
33+ )
34+ def start (
35+ use_example : bool ,
36+ no_ui : bool ,
37+ from_yaml : str | None = None ,
38+ db_url : str | None = None ,
39+ ) -> None :
3440 """Start the FastAPI Forge server and generate a new project."""
35- if use_example and from_yaml :
36- msg = "Cannot use '--use-example' and '--from-yaml' together."
37- raise click .UsageError (
38- msg ,
39- )
41+ if sum ([use_example , bool (from_yaml ), bool (db_url )]) > 1 :
42+ msg = "Only one of '--use-example', '--from-yaml', or '--db-url' can be used."
43+ raise click .UsageError (msg )
4044
41- yaml_path = None
42- if from_yaml :
43- yaml_path = Path .expanduser (Path (from_yaml )).resolve ()
45+ project_spec = None
4446
45- if not yaml_path . exists () :
46- raise click . FileError ( f"YAML file not found: { yaml_path } " )
47+ if from_yaml :
48+ yaml_path = Path ( from_yaml ). expanduser (). resolve ( )
4749 if not yaml_path .is_file ():
48- raise click .FileError (f"Path is not a file: { yaml_path } " )
50+ raise click .FileError (f"YAML file not found: { yaml_path } " )
51+ project_spec = ProjectLoader (project_path = yaml_path ).load_project_input ()
52+
53+ elif db_url :
54+ project_spec = ProjectLoader .load_project_spec_from_db (
55+ connection_string = db_url ,
56+ )
57+
58+ else :
59+ base_path = Path (__file__ ).parent / "example-projects"
60+ path = base_path / ("game_zone.yaml" if use_example else "empty-service.yaml" )
61+ project_spec = ProjectLoader (project_path = path ).load_project_input ()
4962
50- init (
51- use_example = use_example ,
52- no_ui = no_ui ,
53- yaml_path = yaml_path ,
54- )
63+ init (project_spec = project_spec , no_ui = no_ui )
5564
5665
5766@main .command ()
0 commit comments