refactor: use ProjectConfig model for init command YAML output

This commit is contained in:
Konstantin Fickel 2026-02-20 21:04:13 +01:00
parent c1ad6e6e3c
commit 760eac5a7b
Signed by: kfickel
GPG key ID: A793722F9933C1A5

View file

@ -9,10 +9,11 @@ from typing import Annotated, override
import click import click
import typer import typer
import yaml
from typer.core import TyperGroup from typer.core import TyperGroup
from hokusai.builder import BuildEvent, BuildResult, run_build from hokusai.builder import BuildEvent, BuildResult, run_build
from hokusai.config import ProjectConfig, load_config from hokusai.config import GenerateTargetConfig, ProjectConfig, load_config
from hokusai.graph import build_graph, get_build_order from hokusai.graph import build_graph, get_build_order
from hokusai.providers.registry import get_all_models from hokusai.providers.registry import get_all_models
from hokusai.state import state_filename from hokusai.state import state_filename
@ -255,16 +256,25 @@ def init() -> None:
) )
raise typer.Exit(code=1) raise typer.Exit(code=1)
content = f"""\ config = ProjectConfig(
# {name} - hokusai project targets={
targets: "great_wave.png": GenerateTargetConfig(
great_wave.png: prompt=(
prompt: >- 'A recreation of Hokusai\'s "The Great Wave off Kanagawa",'
A recreation of Hokusai's "The Great Wave off Kanagawa", but instead of " but instead of boats and people, paint brushes, canvases,"
boats and people, paint brushes, canvases, and framed paintings are " and framed paintings are swimming and tumbling in the"
swimming and tumbling in the towering wave. " towering wave."
""" ),
_ = dest.write_text(content) ),
},
)
header = f"# {name} - hokusai project\n"
body = yaml.dump(
config.model_dump(exclude_defaults=True),
default_flow_style=False,
sort_keys=False,
)
_ = dest.write_text(header + body)
click.echo(click.style(" created ", fg="green") + click.style(filename, bold=True)) click.echo(click.style(" created ", fg="green") + click.style(filename, bold=True))