Source code for codegen.spec
"""Generated-file output type."""
from dataclasses import dataclass
from typing import Literal
[docs]
@dataclass(frozen=True)
class GeneratedFile:
"""Immutable final output -- a path and its content.
Attributes:
path: Output path relative to the output directory.
content: File contents as a string.
if_exists: Per-file write policy honored by
:func:`codegen.output.write_files`. ``"overwrite"``
(the default) always replaces the target on disk --
the historical behaviour every be scaffold output
relied on. ``"skip"`` writes the file only if it
does not yet exist; right for one-shot scaffolding
(e.g. be_root's bootstrap) where users edit the
file post-generation and a re-run should be
non-destructive. ``--force`` / ``--force-paths`` on
the CLI override ``"skip"`` back to ``"overwrite"``
for the affected files.
executable: When ``True``,
:func:`codegen.output.write_files` chmods the emitted
file ``+x`` (user/group/other) so it can be invoked as
``./path/to/file`` rather than ``bash path/to/file``.
Pairs with shebang-bearing shell scripts emitted
alongside a justfile or package.json.
"""
path: str
content: str
if_exists: Literal["overwrite", "skip"] = "overwrite"
executable: bool = False