blob: 779854b58cdbcfaac87b9a493eefb53974c1e1a1 [file] [log] [blame]
cue eval templates.cue
cmp stdout expect-stdout-cue
-- frontmatter.toml --
title = "Templates"
description = ""
-- text.md --
<!-- jba: this is not in the spec, aside from the TemplateLabel grammar rule. -->
One of CUE's most powerful features is templates.
A template defines a value to be unified with each field of a struct.
The template's identifier (in angular brackets) is bound to name of each
of its sibling fields and is visible within the template value
that is unified with each of the siblings.
-- templates.cue --
// The following struct is unified with all elements in job.
// The name of each element is bound to Name and visible in the struct.
job <Name>: {
name: Name
replicas: uint | *1
command: string
}
job list command: "ls"
job nginx: {
command: "nginx"
replicas: 2
}
-- expect-stdout-cue --
job: {
list: {
name: "list"
replicas: 1
command: "ls"
}
nginx: {
name: "nginx"
replicas: 2
command: "nginx"
}
}