This guide demonstrates how to include CUE files in an evaluation conditionally, using build attributes.
Our example CUE package is composed of four files:
@if(foo)
package example
"data from foo.cue": true@if(!bar)
package example
"data from bar.cue": true@if((foo && !bar) || (!foo && bar))
package example
"data from qux.cue": truebaz.cue
package example
"data from baz.cue": trueThe first three of these files contain
build attributes,
which control if the
file’s contents are included in evaluations of the example package based on
the presence or absence of tags:
foo.cueis only included when thefootag is present.bar.cueis only included when thebartag is not present.qux.cueis only included when one of thebarorfootags is present (but not when both or neither are present).baz.cueis always included.
The following cue export invocations all specify different tags to change the
evaluation as described above:
TERMINAL
$ cue export
{
"data from bar.cue": true,
"data from baz.cue": true
}
$ cue export -t foo
{
"data from bar.cue": true,
"data from baz.cue": true,
"data from foo.cue": true,
"data from qux.cue": true
}
$ cue export -t bar
{
"data from baz.cue": true,
"data from qux.cue": true
}
$ cue export -t foo -t bar
{
"data from baz.cue": true,
"data from foo.cue": true
}The
foo and bar tags are only aligned with their respective filenames to
help you understand their relationships in this example. Tags and filenames
do not need to overlap in any way –
they are entirely unrelated strings.Related content
- Reference: cue help injection
– injecting tags and values into
cuecommand invocations