doc/tutorial/basics: include commands to run
To give the user a clue on how to get the output.
Change-Id: I2fb92d08599c95b7b1cbd70e8f41d2760e359c14
Reviewed-on: https://cue-review.googlesource.com/c/1580
Reviewed-by: Marcel van Lohuizen <mpvl@google.com>
diff --git a/doc/tutorial/basics/aliases.md b/doc/tutorial/basics/aliases.md
index ef96dcf..66f5b71 100644
--- a/doc/tutorial/basics/aliases.md
+++ b/doc/tutorial/basics/aliases.md
@@ -12,6 +12,7 @@
struct, and they do not appear in the output.
<!-- CUE editor -->
+_alias.cue:_
```
A = a // A is an alias for a
a: {
@@ -27,6 +28,7 @@
```
<!-- result -->
+`$ cue eval alias.cue`
```
a: {
d: 3
diff --git a/doc/tutorial/basics/bottom.md b/doc/tutorial/basics/bottom.md
index 8e1bf02..e86cfae 100644
--- a/doc/tutorial/basics/bottom.md
+++ b/doc/tutorial/basics/bottom.md
@@ -16,6 +16,7 @@
whereas `_|_` is not.
<!-- CUE editor -->
+_bottom.cue:_
```
a: 4
a: 5
@@ -28,6 +29,7 @@
```
<!-- result -->
+`$ cue eval -i bottom.cue`
```
a: _|_
l: _|_
diff --git a/doc/tutorial/basics/bytes.md b/doc/tutorial/basics/bytes.md
index 281d4a2..81b782b 100644
--- a/doc/tutorial/basics/bytes.md
+++ b/doc/tutorial/basics/bytes.md
@@ -14,11 +14,13 @@
<!-- jba: this contradicts the spec, which has \nnn (no leading zero) -->
<!-- CUE editor -->
+_bytes.cue:_
```
a: '\x03abc'
```
<!-- JSON result -->
+`$ cue export bytes.cue`
```json
{
a: "A2FiYw=="
diff --git a/doc/tutorial/basics/coalesce.md b/doc/tutorial/basics/coalesce.md
index 4c15e62..a3b64bd 100644
--- a/doc/tutorial/basics/coalesce.md
+++ b/doc/tutorial/basics/coalesce.md
@@ -26,6 +26,7 @@
the result is not of the desired type.
<!-- CUE editor -->
+_coalesce.cue:_
```
list: [ "Cat", "Mouse", "Dog" ]
@@ -37,6 +38,7 @@
```
<!-- result -->
+`$ cue eval coalesce.cue`
```
list: [ "Cat", "Mouse", "Dog" ]
diff --git a/doc/tutorial/basics/commas.md b/doc/tutorial/basics/commas.md
index 66c31fc..e39dae3 100644
--- a/doc/tutorial/basics/commas.md
+++ b/doc/tutorial/basics/commas.md
@@ -14,6 +14,7 @@
of simple rules._
<!-- CUE editor -->
+_commas.cue:_
```
{
one: 1
@@ -25,6 +26,7 @@
<!-- JSON result -->
+`$ cue export commas.cue`
```json
{
"one": 1,
diff --git a/doc/tutorial/basics/commaslists.md b/doc/tutorial/basics/commaslists.md
index 710a7ff..c109962 100644
--- a/doc/tutorial/basics/commaslists.md
+++ b/doc/tutorial/basics/commaslists.md
@@ -9,6 +9,7 @@
The last element of a list may also have a comma.
<!-- CUE editor -->
+_commas2.cue:_
```
[
1,
@@ -18,6 +19,7 @@
```
<!-- JSON result -->
+`$ cue export commas2.cue`
```json
[
1,
diff --git a/doc/tutorial/basics/comments.md b/doc/tutorial/basics/comments.md
index 256e5b1..5acb4ec 100644
--- a/doc/tutorial/basics/comments.md
+++ b/doc/tutorial/basics/comments.md
@@ -7,6 +7,7 @@
CUE supports C-style block and line comments.
<!-- CUE editor -->
+_comments.cue:_
```
// whole numbers
one: 1
@@ -18,6 +19,7 @@
```
<!-- JSON result -->
+`$ cue export comments.cue`
```json
{
"one": 1,
diff --git a/doc/tutorial/basics/conditional.md b/doc/tutorial/basics/conditional.md
index 100ff7c..571efb8 100644
--- a/doc/tutorial/basics/conditional.md
+++ b/doc/tutorial/basics/conditional.md
@@ -12,6 +12,7 @@
<!-- CUE editor -->
+_conditional.cue:_
```
price: float
@@ -22,6 +23,7 @@
```
<!-- result -->
+`$ cue eval conditional.cue`
```
price: 200
justification: string
diff --git a/doc/tutorial/basics/curly.md b/doc/tutorial/basics/curly.md
index 0c7839e..b19dcf9 100644
--- a/doc/tutorial/basics/curly.md
+++ b/doc/tutorial/basics/curly.md
@@ -8,6 +8,8 @@
CUE also allows both, which has a specific meaning.
[We will come back to that later](emit.md).
+<!-- CUE editor -->
+_curly.cue:_
```
one: 1
two: 2
@@ -16,6 +18,7 @@
```
<!-- JSON result -->
+`$ cue export curly.cue`
```json
{
"one": 1,
diff --git a/doc/tutorial/basics/cycle.md b/doc/tutorial/basics/cycle.md
index c9cc4c1..4eda301 100644
--- a/doc/tutorial/basics/cycle.md
+++ b/doc/tutorial/basics/cycle.md
@@ -16,6 +16,7 @@
<!-- CUE editor -->
+_cycle.cue:_
```
// CUE knows how to resolve the following:
x: 200
@@ -28,6 +29,7 @@
```
<!-- result -->
+`$ cue eval -i cycle.cue`
```
x: 200
y: 100
diff --git a/doc/tutorial/basics/cycleref.md b/doc/tutorial/basics/cycleref.md
index f893afd..3f559ef 100644
--- a/doc/tutorial/basics/cycleref.md
+++ b/doc/tutorial/basics/cycleref.md
@@ -10,6 +10,7 @@
merging them ad infinitum.
<!-- CUE editor -->
+_cycleref.cue:_
```
labels: selectors
labels: {app: "foo"}
@@ -19,6 +20,7 @@
```
<!-- result -->
+`$ cue eval cycleref.cue`
```
labels: {app: "foo", name: "bar"}
selectors: {app: "foo", name: "bar"}
diff --git a/doc/tutorial/basics/defaults.md b/doc/tutorial/basics/defaults.md
index a7e59ca..0c4d3bc 100644
--- a/doc/tutorial/basics/defaults.md
+++ b/doc/tutorial/basics/defaults.md
@@ -1,4 +1,4 @@
-[TOC](Readme.md) [Prev](disjunctions.md) [Next](disjstruct.md)
+[TOC](Readme.md) [Prev](disjunctions.md) [Next](sumstruct.md)
_Types ~~and~~ are Values_
@@ -15,6 +15,7 @@
specify either `"tcp"` or `"udp"` as if no marks were given.
<!-- CUE editor -->
+_defaults.cue:_
```
// any positive number, 1 is the default
replicas: uint | *1
@@ -25,6 +26,7 @@
```
<!-- result -->
+`$ cue eval defaults.cue`
```
replicas: 1
protocol: *"tcp" | *"udp"
diff --git a/doc/tutorial/basics/duplicates.md b/doc/tutorial/basics/duplicates.md
index 7d754cf..08a2d03 100644
--- a/doc/tutorial/basics/duplicates.md
+++ b/doc/tutorial/basics/duplicates.md
@@ -14,6 +14,7 @@
([we discuss open-ended lists later](lists.md).)
<!-- CUE editor -->
+_dup.cue:_
```
a: 4
a: 4
@@ -30,6 +31,7 @@
```
<!-- result -->
+`$ cue eval dup.cue`
```
a: 4
s: {
diff --git a/doc/tutorial/basics/emit.md b/doc/tutorial/basics/emit.md
index 03e25bf..d5cca51 100644
--- a/doc/tutorial/basics/emit.md
+++ b/doc/tutorial/basics/emit.md
@@ -18,6 +18,7 @@
of defining structs light.
<!-- CUE editor -->
+_emit.cue:_
```
{
a: A
@@ -29,6 +30,7 @@
```
<!-- result -->
+`$ cue eval emit.cue`
```
a: 1
b: 2
diff --git a/doc/tutorial/basics/fieldcomp.md b/doc/tutorial/basics/fieldcomp.md
index 1f42a30..f2443f3 100644
--- a/doc/tutorial/basics/fieldcomp.md
+++ b/doc/tutorial/basics/fieldcomp.md
@@ -10,6 +10,7 @@
Instead, one must use indexing.
<!-- CUE editor -->
+_fieldcomp.cue:_
```
import "strings"
@@ -25,6 +26,7 @@
```
<!-- result -->
+`$ cue eval fieldcomp.cue`
```
barcelona: {
pos: 1
diff --git a/doc/tutorial/basics/fieldname.md b/doc/tutorial/basics/fieldname.md
index ab33ac9..944b724 100644
--- a/doc/tutorial/basics/fieldname.md
+++ b/doc/tutorial/basics/fieldname.md
@@ -12,6 +12,7 @@
special characters and does not start with a number:
<!-- CUE editor -->
+_fieldname.cue:_
```
{
one: 1,
@@ -22,6 +23,7 @@
```
<!-- JSON result -->
+`$ cue export fieldname.cue`
```json
{
"one": 1,
diff --git a/doc/tutorial/basics/fold.md b/doc/tutorial/basics/fold.md
index 952c240..cb1eb0d 100644
--- a/doc/tutorial/basics/fold.md
+++ b/doc/tutorial/basics/fold.md
@@ -7,11 +7,13 @@
CUE allows a shorthand for structs with single members.
<!-- CUE editor -->
+_fold.cue:_
```
outer middle inner: 3
```
<!-- JSON result -->
+`$ cue export fold.cue`
```json
{
"outer": {
diff --git a/doc/tutorial/basics/foldany.md b/doc/tutorial/basics/foldany.md
index b933eb2..0b6c938 100644
--- a/doc/tutorial/basics/foldany.md
+++ b/doc/tutorial/basics/foldany.md
@@ -10,12 +10,14 @@
path-leaf pairs without using any curly braces.
<!-- CUE editor -->
+_foldany.cue:_
```
outer middle1 inner: 3
outer middle2 inner: 7
```
<!-- JSON result -->
+`$ cue export foldany.cue`
```json
{
"outer": {
diff --git a/doc/tutorial/basics/hidden.md b/doc/tutorial/basics/hidden.md
index 03cea5e..02c74a4 100644
--- a/doc/tutorial/basics/hidden.md
+++ b/doc/tutorial/basics/hidden.md
@@ -13,6 +13,7 @@
with an underscore.
<!-- CUE editor -->
+_hidden.cue:_
```
"_foo": 2
_foo: 3
@@ -20,7 +21,10 @@
```
<!-- result -->
+`$ cue export hidden.cue`
```
-"_foo": 2
-foo: 4
+{
+ "_foo": 2,
+ "foo": 4
+}
```
diff --git a/doc/tutorial/basics/imports.md b/doc/tutorial/basics/imports.md
index 025b47b..03b923a 100644
--- a/doc/tutorial/basics/imports.md
+++ b/doc/tutorial/basics/imports.md
@@ -21,6 +21,7 @@
But it is good style to use the factored import statement.
<!-- CUE editor -->
+_imports.cue:_
```
import (
"encoding/json"
@@ -31,6 +32,7 @@
```
<!-- result -->
+`$ cue eval imports.cue`
```
data: "{\"a\":2.6457513110645907}"
```
\ No newline at end of file
diff --git a/doc/tutorial/basics/interpolation.md b/doc/tutorial/basics/interpolation.md
index ba58af1..b13afbd 100644
--- a/doc/tutorial/basics/interpolation.md
+++ b/doc/tutorial/basics/interpolation.md
@@ -10,6 +10,7 @@
Interpolation may also be used in multiline string and byte literals.
<!-- CUE editor -->
+_interpolation.cue:_
```
"You are \( cost - budget ) dollars over budget!"
@@ -18,6 +19,7 @@
```
<!-- result -->
+`$ cue eval interpolation.cue`
```
"You are 14 dollars over budget!"
```
\ No newline at end of file
diff --git a/doc/tutorial/basics/interpolfield.md b/doc/tutorial/basics/interpolfield.md
index a4140e5..dd07c22 100644
--- a/doc/tutorial/basics/interpolfield.md
+++ b/doc/tutorial/basics/interpolfield.md
@@ -9,6 +9,7 @@
One cannot refer to generated fields with references.
<!-- CUE editor -->
+_- genfield.cue:_
```
sandwich: {
type: "Cheese"
@@ -19,6 +20,7 @@
```
<!-- result -->
+`$ cue eval -i genfield.cue`
```
sandwich: {
type: "Cheese"
diff --git a/doc/tutorial/basics/listcomp.md b/doc/tutorial/basics/listcomp.md
index 835f704..7d465fb 100644
--- a/doc/tutorial/basics/listcomp.md
+++ b/doc/tutorial/basics/listcomp.md
@@ -10,6 +10,7 @@
<!-- CUE editor -->
+_listcomp.cue:_
```
[ x*x for x in items if x rem 2 == 0]
@@ -17,6 +18,7 @@
```
<!-- result -->
+`$ cue eval listcomp.cue`
```
[4, 16, 36, 64]
```
\ No newline at end of file
diff --git a/doc/tutorial/basics/lists.md b/doc/tutorial/basics/lists.md
index 812663c..aadcd6d 100644
--- a/doc/tutorial/basics/lists.md
+++ b/doc/tutorial/basics/lists.md
@@ -21,6 +21,7 @@
and an invalid one (`yourIP`).
<!-- CUE editor -->
+_lists.cue:_
```
IP: 4 * [ uint8 ]
@@ -35,6 +36,7 @@
```
<!-- result -->
+`$ cue eval -i lists.cue`
```
IP: [>=0 & <=255, >=0 & <=255, >=0 & <=255, >=0 & <=255]
PrivateIP:
diff --git a/doc/tutorial/basics/numberlit.md b/doc/tutorial/basics/numberlit.md
index 6bad370..382e6b2 100644
--- a/doc/tutorial/basics/numberlit.md
+++ b/doc/tutorial/basics/numberlit.md
@@ -8,6 +8,7 @@
CUE adds a variety of sugar for writing numbers.
<!-- CUE editor -->
+_numlit.cue:_
```
[
1_234, // 1234
@@ -18,6 +19,7 @@
```
<!-- JSON result -->
+`$ cue export numlit.cue`
```json
[
1234,
diff --git a/doc/tutorial/basics/numbers.md b/doc/tutorial/basics/numbers.md
index 442d626..f703f45 100644
--- a/doc/tutorial/basics/numbers.md
+++ b/doc/tutorial/basics/numbers.md
@@ -1,4 +1,4 @@
-[TOC](Readme.md) [Prev](defaults.md) [Next](ranges.md)
+[TOC](Readme.md) [Prev](sumstruct.md) [Next](ranges.md)
_Types ~~and~~ are Values_
@@ -15,6 +15,7 @@
used as an `int` without conversion.
<!-- CUE editor -->
+_numbers.cue:_
```
a: int
a: 4 // type int
@@ -29,6 +30,7 @@
```
<!-- result -->
+`$ cue eval -i numbers.cue`
```
a: 4
b: 4.0
diff --git a/doc/tutorial/basics/operators.md b/doc/tutorial/basics/operators.md
index 12f7e6d..6512c97 100644
--- a/doc/tutorial/basics/operators.md
+++ b/doc/tutorial/basics/operators.md
@@ -12,6 +12,7 @@
and truncated division (`quo` and `rem`).
<!-- CUE editor -->
+_op.cue:_
```
a: 3 / 2 // type float
b: 3 div 2 // type int: Euclidean division
@@ -23,6 +24,7 @@
```
<!-- result -->
+`$ cue eval -i op.cue`
```
a: 1.5
b: 1
diff --git a/doc/tutorial/basics/packages.md b/doc/tutorial/basics/packages.md
index 73b346f..b460e40 100644
--- a/doc/tutorial/basics/packages.md
+++ b/doc/tutorial/basics/packages.md
@@ -17,7 +17,7 @@
in the same outcome, given that order does not matter.
<!-- CUE editor tab 1-->
-File a.cue
+_a.cue:_
```
package config
@@ -26,7 +26,7 @@
```
<!-- CUE editor tab 2-->
-File b.cue
+_b.cue:_
```
package config
@@ -34,7 +34,7 @@
```
<!-- result -->
-Result
+`$ cue eval a.cue b.cue`
```
foo: 100
bar: 200
diff --git a/doc/tutorial/basics/rangedef.md b/doc/tutorial/basics/rangedef.md
index d29e4e8..4c49c6a 100644
--- a/doc/tutorial/basics/rangedef.md
+++ b/doc/tutorial/basics/rangedef.md
@@ -27,6 +27,7 @@
```
<!-- CUE editor -->
+_range.cue:_
```
positive: uint
byte: uint8
@@ -40,6 +41,7 @@
```
<!-- result -->
+`$ cue eval -i range.cue`
```
a: _|_
b: 128
diff --git a/doc/tutorial/basics/ranges.md b/doc/tutorial/basics/ranges.md
index 548845b..5f8fcc8 100644
--- a/doc/tutorial/basics/ranges.md
+++ b/doc/tutorial/basics/ranges.md
@@ -13,6 +13,7 @@
whereas `<0` allows all negative numbers (int or float).
<!-- CUE editor -->
+_bounds.cue:_
```
rn: >=3 & <8 // type int | float
ri: >=3 & <8 & int // type int
@@ -31,6 +32,7 @@
```
<!-- result -->
+`$ cue eval -i bounds.cue`
```
a: 3.5
b: _|_
diff --git a/doc/tutorial/basics/regexp.md b/doc/tutorial/basics/regexp.md
index 08ee835..1b472f6 100644
--- a/doc/tutorial/basics/regexp.md
+++ b/doc/tutorial/basics/regexp.md
@@ -14,6 +14,7 @@
<!-- CUE editor -->
+_regexp.cue:_
```
a: "foo bar" =~ "foo [a-z]{3}"
b: "maze" !~ "^[a-z]{3}$"
@@ -28,6 +29,7 @@
```
<!-- result -->
+`$ cue eval -i regexp.cue`
```
a: true
b: true
diff --git a/doc/tutorial/basics/scopes.md b/doc/tutorial/basics/scopes.md
index f31bed7..429dbfd 100644
--- a/doc/tutorial/basics/scopes.md
+++ b/doc/tutorial/basics/scopes.md
@@ -13,6 +13,7 @@
If there is still no match, it may match a predefined value.
<!-- CUE editor -->
+_scopes.cue:_
```
v: 1
a: {
@@ -26,6 +27,7 @@
```
<!-- result -->
+`$ cue eval scopes.cue`
```
v: 1
a: {
diff --git a/doc/tutorial/basics/selectors.md b/doc/tutorial/basics/selectors.md
index f48c4cf..1547e81 100644
--- a/doc/tutorial/basics/selectors.md
+++ b/doc/tutorial/basics/selectors.md
@@ -10,6 +10,7 @@
<!-- CUE editor -->
+_selectors.cue:_
```
a: {
b: 2
@@ -20,6 +21,7 @@
```
<!-- result -->
+`$ cue eval selectors.cue`
```
a: {
b: 2
diff --git a/doc/tutorial/basics/stringlit.md b/doc/tutorial/basics/stringlit.md
index 33cf7d6..c5e90c6 100644
--- a/doc/tutorial/basics/stringlit.md
+++ b/doc/tutorial/basics/stringlit.md
@@ -15,6 +15,7 @@
Strings may also contain [interpolations](interpolation.md).
<!-- CUE editor -->
+_stringlit.cue:_
```
// 21-bit unicode characters
a: "\U0001F60E" // 😎
@@ -27,9 +28,10 @@
```
<!-- JSON result -->
+`$ cue extract stringlit.cue`
```json
{
- a: "😎"
- b: "Hello\nWorld!"
+ "a": "😎",
+ "b": "Hello\nWorld!"
}
```
diff --git a/doc/tutorial/basics/stringraw.md b/doc/tutorial/basics/stringraw.md
index 6f5b73a..8ea44fa 100644
--- a/doc/tutorial/basics/stringraw.md
+++ b/doc/tutorial/basics/stringraw.md
@@ -13,6 +13,7 @@
Quotes do not have to be escaped in such strings.
<!-- CUE editor -->
+_stringraw.cue:_
```
msg1: #"The sequence "\U0001F604" renders as \#U0001F604."#
@@ -21,11 +22,13 @@
#"\d{3}"#
- This construct works for bytes, strings and their multi-line variants.
+ This construct works for bytes, strings and their
+ multi-line variants.
"""##
```
<!-- JSON result -->
+`$ cue eval stringraw.cue`
```json
{
msg1: "The sequence \"\\U0001F604\" renders as 😄."
@@ -34,7 +37,8 @@
#\"\\d{3}\"#
- This construct works for bytes, strings and their multi-line variants.
+ This construct works for bytes, strings and their
+ multi-line variants.
"""
}
```
diff --git a/doc/tutorial/basics/disjstruct.md b/doc/tutorial/basics/sumstruct.md
similarity index 97%
rename from doc/tutorial/basics/disjstruct.md
rename to doc/tutorial/basics/sumstruct.md
index 5cbc9ac..25e76a4 100644
--- a/doc/tutorial/basics/disjstruct.md
+++ b/doc/tutorial/basics/sumstruct.md
@@ -10,6 +10,7 @@
has an exit on level 0 and 1, but not on any other floor.
<!-- CUE editor -->
+_sumstruct.cue:_
```
// floor defines the specs of a floor in some house.
floor: {
diff --git a/doc/tutorial/basics/templates.md b/doc/tutorial/basics/templates.md
index bd40c2a..154e997 100644
--- a/doc/tutorial/basics/templates.md
+++ b/doc/tutorial/basics/templates.md
@@ -13,6 +13,8 @@
of its sibling fields and is visible within the template value
that is unified with each of the siblings.
+<!-- CUE editor -->
+_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.
@@ -30,6 +32,8 @@
}
```
+<!-- JSON result -->
+`$ cue eval templates.cue`
```
job: {
list: {
diff --git a/doc/tutorial/basics/types.md b/doc/tutorial/basics/types.md
index e0f80da..aa8c870 100644
--- a/doc/tutorial/basics/types.md
+++ b/doc/tutorial/basics/types.md
@@ -36,6 +36,7 @@
<!-- CUE editor -->
+_types.cue:_
```
point: {
x: float
@@ -52,6 +53,7 @@
```
<!-- result -->
+`$ cue eval types.cue`
```
point: {
x: float
diff --git a/doc/tutorial/basics/unification.md b/doc/tutorial/basics/unification.md
index bbca5ef..b28ecf8 100644
--- a/doc/tutorial/basics/unification.md
+++ b/doc/tutorial/basics/unification.md
@@ -16,6 +16,7 @@
in any order always gives the same result.
<!-- CUE editor -->
+_unification.cue:_
```
a: { x: 1, y: 2 }
b: { y: 2, z: 3 }
@@ -27,6 +28,7 @@
```
<!-- result -->
+`$ cue eval -i unification.cue`
```
a: { x: 1, y: 2 }
b: { y: 2, z: 3 }