$ cue export json.cue
{
" one" : 1,
" two" : 2,
" two-and-a-half" : 2.5,
" list" : [
1,
2,
3
]
}
$ cue eval dup.cue
a: 4
s: {
b: 2
c: 2
}
l: [1, 2]
$ cue eval check.cue
schema: {
name: string
age: int
human: true
}
viola: {
name: " Viola"
age: 38
human: true
}
$ cue export json.cue
{
" one" : 1,
" two" : 2,
" two-and-a-half" : 2.5,
" list" : [
1,
2,
3
]
}
cue export schema.cue
{
" lossy" : {
" address" : " 1.2.3.4" ,
" port" : 8888,
" protocol" : " udp"
}
}
$ cue vet schema.cue data.yaml
languages.1.name: invalid value " dutch" (out of bound =~ " ^\\ p{Lu}" ):
./schema.cue:3:8
./data.yaml:5:12
$ cue eval -i order.cue
a: {
x: 1
y: 2
}
b: {
x: 1
y: 2
}
Folding of Single-Field Structs
$ cue export fold.cue
{
" outer" : {
" middle1" : {
" inner" : 3
},
" middle2" : {
" inner" : 7
}
}
}
cue eval types.cue
point: {
x: number
y: number
}
xaxis: {
x: number
y: 0
}
yaxis: {
x: 0
y: number
}
origin: {
x: 0
y: 0
}
$ cue eval -i bottom.cue
a: _| _ // a: conflicting values 5 and 4
l: [1, _| _, // l.1: conflicting values 3 and 2
]
list: [0, 1, 2]
val: _| _ // val: index out of range [3] with length 3
$ cue eval bottom.cue
a: conflicting values 5 and 4:
./bottom.cue:1:4
./bottom.cue:2:4
l.1: conflicting values 3 and 2:
./bottom.cue:4:9
./bottom.cue:5:9
val: index out of range [3] with length 3:
./bottom.cue:8:11
$ cue vet bottom.cue
a: conflicting values 5 and 4:
./bottom.cue:1:4
./bottom.cue:2:4
l.1: conflicting values 3 and 2:
./bottom.cue:4:9
./bottom.cue:5:9
val: index out of range [3] with length 3:
./bottom.cue:8:11
$ cue eval -i numbers.cue
a: 4
b: 4.0
c: _| _ // c: conflicting values int and 4.0 (mismatched types int and float)
d: 4
e: [1_234, 5M, 1.5Gi, 0x1000_0000]
$ cue export stringlit.cue
{
" a" : " 😎" ,
" b" : " Hello\nWorld!"
}
msg1: # "The sequence "\U0001F604" renders as \#U0001F604."#
msg2: # #"""
A regular expression can conveniently be written as:
# "\d{3}"#
This construct works for bytes, strings and their
multi-line variants.
" " " ##
$ cue export bytes.cue
{
" a" : " A2FiYw=="
}
$ echo " A2FiYw==" | base64 -d
abc%
cue eval -i structs.cue
a: {
field: int
}
b: {
field: int
feild: _| _ // b.feild: field not allowed
}
$ cue eval -ic defs.cue
msg: " Hello world!"
a: {
field: 3
}
err: {
field: int
feild: _| _ // err.feild: field not allowed
}
$ cue eval -c structs.cue
b: {
foo: 3
}
$ cue eval disjunctions.cue
# Conn: {
address: string
port: int
protocol: " tcp" | " udp"
}
lossy: {
address: " 1.2.3.4"
port: 8888
protocol: " udp"
}
$ cue eval defaults.cue
replicas: 1
protocol: " tcp" | " udp"
$ cue eval sumstruct.cue
floor: {
level: 0 | 1
hasExit: true
} | {
level: -1 | 2 | 3
hasExit: false
}
$ cue eval -ic bounds.cue
a: 3.5
b: _| _ // b: conflicting values int and 3.5 (mismatched types int and float)
c: 3
d: " ma"
e: _| _ // e: invalid value " mu" (out of bound < " mo" )
r1: > =5 & < 8
$ cue eval -ic bound.cue
a: _| _ // a: invalid value -1 (out of bound > =0)
b: 128
c: 2000000000
$ cue eval -i lists.cue
IP: [uint8, uint8, uint8, uint8]
PrivateIP: [10, uint8, uint8, uint8] | [192, 168, uint8, uint8] | [172, uint & >= 16 & <= 32, uint8, uint8]
myIP: [10, 2, 3, 4]
yourIP: _| _ // yourIP: 3 errors in empty disjunction: (and 3 more errors)
$ cue eval templates.cue
job: {
list: {
name: " list"
replicas: 1
command: " ls"
}
nginx: {
name: " nginx"
command: " nginx"
replicas: 2
}
}
$ cue eval scopes.cue
v: 1
a: {
v: 2
c: 1
b: 2
}
b: 1
$ cue eval selectors.cue
a: {
b: 2
" c-e" : 5
}
v: 2
w: 5
$ cue eval alias.cue
a: {
d: 3
}
b: {
a: {
c: 3
}
}
$ cue export emit.cue
" Hello world!"
$ cue eval -i -c cycle.cue
x: 200
y: 100
a: b + 100
b: a - 100
$ cue eval cycleref.cue
labels: {
app: " foo"
name: " bar"
}
selectors: {
name: " bar"
app: " foo"
}
$ cue export hidden.cue
{
" _foo" : 2,
" foo" : 4
}
$ cue eval -i op.cue
a: 1.5
b: 1
c: " blahblahblah"
d: [1, 2, 3, 1, 2, 3, 1, 2, 3]
e: true
$ cue eval interpolation.cue
" You are 14 dollars over budget!"
# cost: 102
# budget: 88
$ cue export interpolation.cue
" You are 14 dollars over budget!"
Interpolation of Field Names
$ cue eval genfield.cue
sandwich.butterAndCheese: reference " hasCheese" not found:
./genfield.cue:5:35
# comment out butterAndCheese: hasButter && hasCheese
$ cue eval genfield.cue
sandwich: {
type: " Cheese"
hasCheese: true
hasButter: true
}
$ cue export listcomp.cue
[
4,
16,
36,
64
]
$ cue eval -c fieldcomp.cue
barcelona: {
pos: 1
name: " Barcelona"
nameLen: 9
}
shanghai: {
pos: 2
name: " Shanghai"
nameLen: 8
}
munich: {
pos: 3
name: " Munich"
nameLen: 6
}
$ cue eval conditional.cue
justification: string
price: 200
$ cue export conditional.cue
justification: incomplete value string:
./conditional.cue:5:20
# add justification: "sorry"
$ cue export conditional.cue
{
" price" : 200,
" justification" : " sorry"
}
$ cue eval -i regexp.cue
a: true
b: true
c: =~ " ^[a-z]{3}$"
d: " foo"
e: _| _ // e: invalid value " foo bar" (out of bound =~ " ^[a-z]{3}$" )
$ cue eval coalesce.cue
list: [" Cat" , " Mouse" , " Dog" ]
a: " Cat"
b: " None"
n: [null]
v: " default"
$ cue eval a.cue b.cue
foo: 100
bar: 200
$ cue eval imports.cue
data: " {\" a\" :2.6457513110645907}"
$ cd kubernetes/original
$ cue mod init
$ go mod init example.com
go: creating new go.mod: module example.com
go: to add module requirements and sums:
go mod tidy
$ cd services
$ cue import ./...
path, list, or files flag needed to handle multiple objects in file ./services/frontend/bartender/kube.yaml
$ cue import ./... -p kube
path, list, or files flag needed to handle multiple objects in file ./services/frontend/bartender/kube.yaml
$ cue import ./... -p kube -l ' strings.ToCamel(kind)' -l metadata.name -f
$ $ tree . | head
.
├── frontend
│ ├── bartender
│ │ ├── kube.cue
│ │ └── kube.yaml
│ ├── breaddispatcher
│ │ ├── kube.cue
│ │ └── kube.yaml
│ ├── host
│ │ ├── kube.cue
$ cat mon/prometheus/configmap.cue | head
package kube
configMap: prometheus: {
apiVersion: "v1"
kind: "ConfigMap"
metadata: name: "prometheus"
data: {
"alert.rules": """
groups:
- name: rules.yaml
$ cue import ./... -p kube -l ' strings.ToCamel(kind)' -l metadata.name -f -R
$ cat mon/prometheus/configmap.cue | head
package kube
import yaml656e63 "encoding/yaml"
configMap: prometheus: {
apiVersion: "v1"
kind: "ConfigMap"
metadata: name: "prometheus"
data: {
"alert.rules": yaml656e63.Marshal(_cue_alert_rules)
$ cue eval ./mon/prometheus -e configMap.prometheus | head
apiVersion: "v1"
kind: "ConfigMap"
metadata: {
name: "prometheus"
}
data: {
"alert.rules": """
groups:
- name: rules.yaml
rules: