我们先新建一个cue文件:
a: 1.5b: 1+12c: [1, 2, 3]
1、格式化命令
cue fmt hello.cue
这个命令会给我们整理cue文件里面的格式,比如:
a:1.5
b: 1+12,
c:[1, 2, 3]
a: 1.5
b: 1+12
c: [1, 2, 3]
2、校验语法是否正确
cue vet hello.cue
加入你的文件里面出现语法不当,这个命令会输出错的位置,比如:
a: 1.5
b: 1+12
c: ,[1, 2, 3]
$ cue vet hello.cue
expected operand, found ',':
./hello.cue:3:4
3、计算出结果
$ cue eval hello.cue
a: 1.5
b: 13
c: [1, 2, 3]
你会发现 b 的值被计算出来了,我们的文件里面写的是 1+12。
4、计算单个变量的结果
我们只需要在上一个命令基础之上加参数即可:
$ cue eval hello.cue -e b
13
5、导出数据
默认导出的是 json 格式:
$ cue export hello.cue
{
"a": 1.5,
"b": 13,
"c": [
1,
2,
3
]
}
假如你需要导出 yaml 格式,同样只需要在后面加参数即可:
$ cue export hello.cue --out yaml
a: 1.5
b: 13
c:
- 1
- 2
- 3
再假如你只需要导出某个变量,也只需要加 -e 即可:
$ cue export hello.cue -e a --out yaml
1.5
