Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions manage_fastapi/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class ProjectContext(BaseModel):
folder_name: str
packaging: PackageManager

output_dir: str

username: Optional[str] = None
email: Optional[EmailStr] = None

Expand All @@ -42,12 +44,8 @@ class ProjectContext(BaseModel):
@root_validator(pre=True)
def validate_project(cls, values: dict):
try:
values["username"] = subprocess.check_output(
["git", "config", "--get", "user.name"]
)
values["email"] = subprocess.check_output(
["git", "config", "--get", "user.email"]
)
values["username"] = subprocess.check_output(["git", "config", "--get", "user.name"])
values["email"] = subprocess.check_output(["git", "config", "--get", "user.email"])
except subprocess.CalledProcessError:
...
values["folder_name"] = values["name"].lower().replace(" ", "-").strip()
Expand Down
4 changes: 3 additions & 1 deletion manage_fastapi/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@

def fill_template(template_name: str, context: ContextType):
try:
output_dir = context.output_dir
cookiecutter(
os.path.join(TEMPLATES_DIR, template_name),
extra_context=context.dict(),
extra_context=context.dict(exclude={"output_dir"}),
no_input=True,
output_dir=output_dir,
)
except OutputDirExistsException:
typer.echo(f"Folder '{context.folder_name}' already exists. 😞")
Expand Down
5 changes: 3 additions & 2 deletions manage_fastapi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
@app.command(help="Creates a FastAPI project.")
def startproject(
name: str,
output_dir: Optional[str] = typer.Argument(default="."),
interactive: bool = typer.Option(False, help="Run in interactive mode."),
database: Optional[Database] = typer.Option(None, case_sensitive=False),
docker: bool = typer.Option(False),
Expand All @@ -42,6 +43,7 @@ def startproject(
else:
context = ProjectContext(
name=name,
output_dir=output_dir,
packaging=packaging,
python=python,
license=license_,
Expand Down Expand Up @@ -83,5 +85,4 @@ def main(
is_eager=True,
help="Show the Manage FastAPI version information.",
)
):
...
): ...
7 changes: 7 additions & 0 deletions tests/test_startproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,10 @@ def test_startproject_already_exists(tmp_path: Path):
result = runner.invoke(app, ["startproject", "potato"])
assert result.output == ALREADY_EXISTS
assert result.exit_code == 0


def test_startproject_with_output_dir(tmp_path: Path):
with runner.isolated_filesystem(temp_dir=tmp_path):
result = runner.invoke(app, ["startproject", "potato", "myproject/potato"])
assert result.output == CREATED_SUCCESSFULLY
assert result.exit_code == 0