Skip to content

feat(template): offline cy template render command#459

Open
fhacloid wants to merge 3 commits into
developfrom
feat/cli-template-render-offline
Open

feat(template): offline cy template render command#459
fhacloid wants to merge 3 commits into
developfrom
feat/cli-template-render-offline

Conversation

@fhacloid

Copy link
Copy Markdown
Contributor

What

Adds cy template render — render Cycloid stack templates locally, with no backend. This is one of the last cornerstones for local stack editing + debugging, for humans and agents alike.

How

Engine (vendored). The interpolation engine is copied from youdeploy-http-api into internal/templating/engine as a thin adapter — yderr/errtmpl swapped for the stdlib (errors/fmt), everything else byte-identical. See engine/VENDORED.md for the source commit and the delete-and-import plan for when the CLI merges into the backend. Keeping the engine untouched means offline output stays parity-testable against the backend.

CLI wrapper (internal/templating).

  • Layered context input, ascending precedence: component base < context file (JSON/YAML) < stdin/string < --set k=v (highest). Dotted keys nest; maps deep-merge.
  • Placeholder rendering: an unset known variable renders as <placeholder:$name> rather than erroring or rendering empty, so a template can be exercised without a full platform context (this also makes the inventory_jwt guard a no-op offline). Unknown bare references surface as warnings (likely typos).
  • Multi-template input: --file/-f (repeatable), --dir walk, or stdin (-). One JSON Report per template; non-zero exit if any render fails.

Wiring. Flags in internal/cyargs/templating.go; command registered in cmd/root.go (template, aliases tpl/tmpl).

Tests

  • internal/templating/*_test.go — render cases (provided/unset-known/unknown/sprig/inventory_jwt/parse-error/nested), context layering precedence, ParseSet dotted keys, and a YAML deep-merge regression (yaml.v3 nested maps defeated Merge's type assertion → partial --set clobbered siblings; fixed via normalizeContext).
  • e2e/template_test.go--set + placeholder, YAML context-file + dotted override, stdin JSON, parse-error nonzero exit.

Build + vet + golangci-lint --new-from-rev=develop (0 issues) + unit tests all green.

Follow-ups (not in this PR)

Backend templating endpoints (render + context-export), a cy template context verb that pulls a real component's context, remote mode, and the render-parity test that joins the offline and backend paths.

🤖 Generated with Claude Code

fhacloid and others added 3 commits June 12, 2026 14:07
Render Cycloid stack templates locally with no backend, the missing
cornerstone for local stack editing and debugging by humans and agents.

The interpolation engine is vendored from youdeploy-http-api under
internal/templating/engine (thin adapter: yderr/errtmpl swapped for the
stdlib, see VENDORED.md) so offline output is byte-identical to the
backend and stays parity-testable. The CLI wrapper adds:

- layered context input: component base < context file (JSON/YAML) <
  stdin/string < --set k=v (highest), with dotted keys and deep-merge
- placeholder rendering: unset *known* vars render as
  <placeholder:$name> instead of erroring, so a template can be
  exercised without a full platform context; unknown refs warn
- multi-template input via --file (repeatable), --dir walk, or stdin;
  JSON report per template, non-zero exit on any render failure

Flags live in internal/cyargs/templating.go; the command is registered
in cmd/root.go. Unit tests cover render, layering precedence, and the
YAML deep-merge regression; e2e covers the command surface.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
`cy template render` is an experimental offline feature — park it under
`cy beta template render` until the backend render+context endpoints land.
Updates e2e tests, help examples, and changelog entry to match.

Includes collateral gci import-sort and alignment fixes on four files
touched by `make format`.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant