This guide demonstrates how to include CUE files in an evaluation conditionally, using build attributes.

The example CUE package is composed of three files:

@if(foo)
package example

"data from foo.cue": true
@if(!bar)
package example

"data from bar.cue": true
qux.cue
package example

"data from qux.cue": true

Two 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.cue is included only when the foo tag is present.
  • bar.cue is included only when the bar tag is not present.
  • qux.cue is always included.
TERMINAL
$ cue export
{
    "data from bar.cue": true,
    "data from qux.cue": true
}
$ cue export -t foo
{
    "data from bar.cue": true,
    "data from foo.cue": true,
    "data from qux.cue": true
}
$ cue export -t bar
{
    "data from qux.cue": true
}
$ cue export -t foo -t bar
{
    "data from foo.cue": true,
    "data from qux.cue": true
}