Adds project initialization command
All checks were successful
Build Wheels / build (push) Successful in 4m44s
All checks were successful
Build Wheels / build (push) Successful in 4m44s
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.
This commit is contained in:
@@ -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:
|
||||
|
41
src/hdlbuild/commands/init.py
Normal file
41
src/hdlbuild/commands/init.py
Normal file
@@ -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.")
|
Reference in New Issue
Block a user