cue-lang / docs-and-content

A place to discuss, plan, and track documentation on cuelang.org
5 stars 1 forks source link

docs/howto: inject a list value into a CUE evaluation using a tag #163

Open jpluscplusm opened 1 week ago

jpluscplusm commented 1 week ago

From https://cuelang.slack.com/archives/CLT4FD7KP/p1718196611679809:

A Commented CUE guide demonstrating how to pass a list into a CUE evaluation robustly, using a tag containing a stringified JSON list.

exec cue eval foo.cue -t roles='["role1","role2"]'
cmp stdout out
-- foo.cue --
import "encoding/json"

_Roles: *"" | string @tag(roles)
Roles:  json.Unmarshal(_Roles)
-- out --
Roles: ["role1", "role2"]

(Perhaps the default should be "[]"?)