Skip to content

Commit 705cda2

Browse files
committed
Pass data file
1 parent 212653d commit 705cda2

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
---
12
schemas:
2-
- schemas
3+
- schemas
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1+
---
12
project_name:
2-
type: str
3-
help: What is your project name?
3+
type: str
4+
help: What is your project name?
45
generators:
56
type: bool
67
help: Would you like to use generators?
7-
default: no
8+
default: false
89
transforms:
910
type: bool
1011
help: Would you like to use transforms?
11-
default: no
12+
default: false
1213
scripts:
1314
type: bool
1415
help: Would you like to have local scripts?
15-
default: no
16+
default: false
1617
queries:
1718
type: bool
1819
help: Would you like to store queries?
19-
default: no
20+
default: false
2021
menus:
2122
type: bool
2223
help: Would you like to store menus?
23-
default: no
24+
default: false
2425
tests:
2526
type: bool
2627
help: Would you like to have testing?
27-
default: no
28+
default: false
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Changes here will be overwritten by Copier
2+
{{ _copier_answers|to_nice_yaml -}}

infrahub_sdk/ctl/repository.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from __future__ import annotations
22

3+
import asyncio
34
from pathlib import Path
4-
from copier import run_copy
5+
56
import typer
6-
import asyncio
77
import yaml
8+
from copier import run_copy
89
from pydantic import ValidationError
910
from rich.console import Console
1011
from rich.table import Table
@@ -163,9 +164,19 @@ async def list(
163164
@app.command()
164165
async def init(
165166
dst: Path,
167+
data: Path | None = None,
166168
_: str = CONFIG_PARAM,
167169
) -> None:
168170
"""Initialize a new Infrahub repository."""
169171
example_repo = Path(__file__).parent / "example_repo"
170-
await asyncio.to_thread(run_copy, str(example_repo), str(dst))
171-
172+
config_data = None
173+
if data:
174+
try:
175+
with Path.open(data, encoding="utf-8") as f:
176+
config_data = yaml.safe_load(f) # Load YAML contents
177+
typer.echo(f"Loaded config: {config_data}") # Print for debugging
178+
except Exception as e:
179+
typer.echo(f"Error loading YAML file: {e}", err=True)
180+
raise typer.Exit(code=1)
181+
182+
await asyncio.to_thread(run_copy, str(example_repo), str(dst), data=config_data)

0 commit comments

Comments
 (0)