refactor: use ProjectConfig model for init command YAML output
This commit is contained in:
parent
c1ad6e6e3c
commit
760eac5a7b
1 changed files with 21 additions and 11 deletions
|
|
@ -9,10 +9,11 @@ from typing import Annotated, override
|
|||
|
||||
import click
|
||||
import typer
|
||||
import yaml
|
||||
from typer.core import TyperGroup
|
||||
|
||||
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.providers.registry import get_all_models
|
||||
from hokusai.state import state_filename
|
||||
|
|
@ -255,16 +256,25 @@ def init() -> None:
|
|||
)
|
||||
raise typer.Exit(code=1)
|
||||
|
||||
content = f"""\
|
||||
# {name} - hokusai project
|
||||
targets:
|
||||
great_wave.png:
|
||||
prompt: >-
|
||||
A recreation of Hokusai's "The Great Wave off Kanagawa", but instead of
|
||||
boats and people, paint brushes, canvases, and framed paintings are
|
||||
swimming and tumbling in the towering wave.
|
||||
"""
|
||||
_ = dest.write_text(content)
|
||||
config = ProjectConfig(
|
||||
targets={
|
||||
"great_wave.png": GenerateTargetConfig(
|
||||
prompt=(
|
||||
'A recreation of Hokusai\'s "The Great Wave off Kanagawa",'
|
||||
" but instead of boats and people, paint brushes, canvases,"
|
||||
" and framed paintings are swimming and tumbling in the"
|
||||
" towering wave."
|
||||
),
|
||||
),
|
||||
},
|
||||
)
|
||||
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))
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue