cue-lang / docs-and-content

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

docs/howto: Exporting multiple YAML documents in a single file #106

Open jpluscplusm opened 6 months ago

jpluscplusm commented 6 months ago

Slack thread: https://cuelang.slack.com/archives/CLT3ULF6C/p1706537456419989?thread_ts=1706535669.111589&cid=CLT3ULF6C

Original thread (click to expand) #### Erik Mogensen Is it at all possible to get cue to export a list of documents, sort of the opposite of `cue import -l foo -l bar`? i.e. something like `cue export -e '*.*'` or something, and emit e.g. several yaml documents (`--merge=false` style)... #### Martin Hansen I think the idea is that you use a Cue command to do that: ``` package control import ( "encoding/yaml" "tool/cli" ) objects: [for v in objectSets for x in v {x}] objectSets: [ apps, ] command: render: { task: print: cli.Print & { text: yaml.MarshalStream(objects) } } ``` Something like that :point_up: #### Jonathan Matthews Hey Erik Mogensen :wave: I'm capturing this as an issue so we don't forget to get it documented :slightly_smiling_face: Please could you confirm that when you said > and emit e.g. several yaml documents what you actively want to see is a single multi-document stream, e.g. ``` bar: baz: 4 --- blog: x: 1 "y": 2 z: 3 ``` #### Erik Mogensen Correct. Essentially output like if you import and emit several documents with `--merge=false`.

A howto guide that demonstrates a more real-world example of the following. Ideally it would demonstrate it with a cue export, but could use a cue command if required.

Unresolved question: given lexical scoping, it might be (more) possible to demo with cue export if the fields weren't at the top-level. Should we show this, and leave the top-level problem open for a future, more complex guide? Or should this guide only demo a universally applicable solution?

Given this CUE

a: b: c: 1
d: e: f: 2
g: h: i: 3

Produce this YAML

a:
  b:
    c: 1
---
d:
  e:
    f: 2
---
g:
  h:
    i: 3