genutil

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package genutil holds small shared helpers for the generation commands (theme resolution from props, flag-default fallbacks, output paths).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FirstNonEmpty

func FirstNonEmpty(vals ...string) string

FirstNonEmpty returns the first non-empty string.

func FirstNonZero

func FirstNonZero(vals ...float64) float64

FirstNonZero returns the first non-zero float.

func OrDefault

func OrDefault(s, def string) string

OrDefault returns s, or def when s is empty.

func Reader added in v0.9.0

func Reader(ctx context.Context, p *props.Props) config.Reader

Reader returns the config every generator should read through: keryx's composed store, or whatever store props carries when there is nothing to compose from (the studio's project-scoped props, or a test's injected store).

Exported so avatars, providers and storage resolve through the SAME layers as themes. They each take a config.Reader and inherit whatever their caller has — so a caller reaching for props.Config directly is how one area silently ends up reading different files from another (spec 0048).

func RefImageFromBytes

func RefImageFromBytes(data []byte) provider.RefImage

RefImageFromBytes builds an image-to-image reference from raw bytes, detecting its MIME type from content. The one place reference photos become provider input (portraits, avatars, card actor-direction).

func ResolveTheme

func ResolveTheme(ctx context.Context, p *props.Props, keyword string) (theme.Theme, error)

ResolveTheme loads the catalog from the active config and resolves a theme by keyword (empty → the configured default).

It resolves through the LAYERED theme store (~/.keryx/themes.yaml, the legacy ~/.keryx/config.yaml, and the project's .keryx.yaml) rather than p.Config, whose file list does not include themes.yaml — reading through that would make a promoted theme invisible to every generator (spec 0042 §3.6).

There is no target argument, and no type. A theme is an aesthetic and resolves the same way whatever is being generated; the TARGET enters later, at theme.Theme.PromptFor, where it supplies the format (spec 0047 D4).

func ThemeForGen

func ThemeForGen(ctx context.Context, p *props.Props, keyword string) (theme.Theme, error)

ThemeForGen resolves a theme for a generator, hard-failing on an explicitly named but unregistered keyword (CLI-TEST-REPORT B-10 — an unknown --theme must not silently fall back to the zero theme), while tolerating "no keyword + no configured default" as an unthemed render (the zero theme). Load errors propagate.

The zero theme is not an empty prompt: under 0047 it still yields the target's format, the author's subject and the hardening, which is a sensible bare render. keryx seeds no themes (0046), so a fresh install has to be able to generate.

func WriteFile

func WriteFile(fs afero.Fs, path string, data []byte) error

WriteFile writes generated artefact bytes to path, creating the parent directory first — a fresh workspace doesn't pre-create the per-kind takes/ dirs, and on a real OS filesystem afero.WriteFile won't make them, so without this the provider call (paid) succeeds and the bytes are then dropped (CLI-TEST-REPORT B-1).

func WriteImages

func WriteImages(fs afero.Fs, prefix string, imgs []provider.Image) ([]string, error)

WriteImages writes candidate images to "<prefix>-<i>.<format>" and returns the paths.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL