From 7cf69aa16f79ff91dca5d251955c563e3bfa2a0f Mon Sep 17 00:00:00 2001 From: Max P Date: Sun, 27 Apr 2025 17:58:11 +0000 Subject: [PATCH] Adds project initialization command Introduces an `init` command to initialize new HDLBuild projects. Includes creation of default `.gitignore` and `project.yml` files from templates if they do not already exist. Updates command registration to include the new `init` command. --- src/hdlbuild/commands/commands.py | 4 ++- src/hdlbuild/commands/init.py | 41 +++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/hdlbuild/commands/init.py diff --git a/src/hdlbuild/commands/commands.py b/src/hdlbuild/commands/commands.py index 565562d..80d1472 100644 --- a/src/hdlbuild/commands/commands.py +++ b/src/hdlbuild/commands/commands.py @@ -1,6 +1,7 @@ from hdlbuild.commands.build import BuildCommand from hdlbuild.commands.clean import CleanCommand from hdlbuild.commands.dep import DepCommand +from hdlbuild.commands.init import InitCommand from hdlbuild.commands.test import TestCommand @@ -10,7 +11,8 @@ def register_commands(subparsers): CleanCommand(), BuildCommand(), DepCommand(), - TestCommand() + TestCommand(), + InitCommand(), ] for command in commands: diff --git a/src/hdlbuild/commands/init.py b/src/hdlbuild/commands/init.py new file mode 100644 index 0000000..6f602b1 --- /dev/null +++ b/src/hdlbuild/commands/init.py @@ -0,0 +1,41 @@ +from pathlib import Path +import shutil +from hdlbuild.dependencies.resolver import DependencyResolver +from hdlbuild.utils.console_utils import ConsoleUtils +from hdlbuild.utils.project_loader import load_project_config + +class InitCommand: + def __init__(self): + self.console_utils = ConsoleUtils("hdlbuild") + self.project = load_project_config() + + def register(self, subparsers): + parser = subparsers.add_parser("init", help="Initialize a new HDLBuild project") + parser.set_defaults(func=self.execute) + + def execute(self, args): + """Initialize a new HDLBuild project.""" + project_dir = Path.cwd() + + # Paths to templates + template_dir = Path(__file__).parent / "templates" + + # .gitignore + gitignore_template = template_dir / "gitignore.template" + gitignore_target = project_dir / ".gitignore" + + if not gitignore_target.exists(): + shutil.copy(gitignore_template, gitignore_target) + self.console_utils.print("Created .gitignore") + else: + self.console_utils.print(".gitignore already exists, skipping.") + + # project.yml + project_yml_template = template_dir / "project.yml.template" + project_yml_target = project_dir / "project.yml" + + if not project_yml_target.exists(): + shutil.copy(project_yml_template, project_yml_target) + self.console_utils.print("Created project.yml") + else: + self.console_utils.print("project.yml already exists, skipping.") \ No newline at end of file