Skip to content

Commit

Permalink
Adds a --populate flag (#15)
Browse files Browse the repository at this point in the history
* Adding --populate flag for existing directories

* Black formatting
  • Loading branch information
LeStarch authored Jan 14, 2025
1 parent 3bb6128 commit 6d1a602
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/fprime_bootstrap/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ def main():
type=str,
help="Version of F´ to checkout (default: latest release)",
)
project_parser.add_argument(
"--populate",
action="store_true",
default=False,
help="Populate an existing direcory with a new F´ project (default: False)",
)

clone_parser = subparsers.add_parser(
"clone", help="Clone an existing remote F´ project"
Expand Down
16 changes: 11 additions & 5 deletions src/fprime_bootstrap/bootstrap_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,18 @@ def bootstrap_project(parsed_args: "argparse.Namespace"):
target_dir = Path(parsed_args.path)
# Ask user for project name
project_name = (
input(f"Project name ({DEFAULT_PROJECT_NAME}): ") or DEFAULT_PROJECT_NAME
(input(f"Project name ({DEFAULT_PROJECT_NAME}): ") or DEFAULT_PROJECT_NAME)
if not parsed_args.populate
else target_dir.name
)
check_project_name(project_name)

project_path = target_dir / project_name
project_path = target_dir / project_name if not parsed_args.populate else target_dir

try:
generate_boilerplate_project(project_path, project_name)
generate_boilerplate_project(
project_path, project_name, populate=parsed_args.populate
)
setup_git_repo(project_path, parsed_args.tag)
if not parsed_args.no_venv:
setup_venv(project_path)
Expand Down Expand Up @@ -178,11 +182,13 @@ def setup_git_repo(project_path: Path, tag: str):
sys.exit(1)


def generate_boilerplate_project(project_path: Path, project_name: str):
def generate_boilerplate_project(
project_path: Path, project_name: str, populate: bool = False
):
"""Generates a new project"""
source = Path(__file__).parent / "templates/fprime-project-template"
# copy files from template into target path
shutil.copytree(source, project_path)
shutil.copytree(source, project_path, dirs_exist_ok=populate)

# Iterate over all template files and replace {{FPRIME_PROJECT_NAME}} placeholder with project_name
for file in project_path.rglob("*-template"):
Expand Down

0 comments on commit 6d1a602

Please sign in to comment.