-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathcue.sh
More file actions
executable file
·102 lines (78 loc) · 2.17 KB
/
cue.sh
File metadata and controls
executable file
·102 lines (78 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env bash
set -euo pipefail
# cue.sh
#
# SUMMARY
#
# CUE utilities.
ROOT=$(git rev-parse --show-toplevel)
CUE_SOURCES="${ROOT}/website/cue"
JSON_OUT="${ROOT}/website/data/docs.json"
list-docs-files() {
find "${CUE_SOURCES}" -name '*.cue'
}
cmd_check() {
${VDEV:-cargo vdev} check docs
}
cmd_list() {
list-docs-files
}
cmd_fmt() {
# Ignore JSON-style cue files generated from VRL source code
list-docs-files | grep -v "${CUE_SOURCES}/reference/remap/functions/" | xargs cue fmt "$@"
}
cmd_vet() {
list-docs-files | xargs cue vet --concrete --all-errors "$@"
}
cmd_eval() {
list-docs-files | xargs cue eval --concrete --all-errors "$@"
}
cmd_export() {
list-docs-files | xargs cue export --all-errors "$@"
}
cmd_build() {
# Display the CUE version for CI debugging purposes
cue version
# The docs JSON file needs to be removed or else CUE errors
rm -f "${JSON_OUT}"
# Build the docs JSON object out of the CUE sources
list-docs-files | xargs cue export --all-errors "$@" --outfile "${JSON_OUT}"
}
usage() {
cat >&2 <<-EOF
Usage: $0 [build|check|fmt|list|vet|eval|export]
Modes:
build - build all of the CUE sources and export them into a Hugo-processable
JSON object
check - check for the CUE sources' correctness
fmt - format all CUE files using the built-in formatter
list - list all the documentation files
vet - check the documentation files and print errors
eval - print the evaluated documentation,
optionally pass the expression to evaluate via "-e EXPRESSION"
export - export the documentation,
optionally pass the expression to evaluate via "-e EXPRESSION"
Examples:
Print the whole documentation in the JSON format:
$0 export
Print the "components.sources.kubernetes_logs" subtree in CUE format:
$0 eval -e components.sources.kubernetes_logs
Print the "cli" subtree in JSON format:
$0 export -e cli
Write all CUE data as JSON to ${JSON_OUT}:
make cue-build
Reformat the CUE sources:
make cue-fmt
EOF
exit 1
}
MODE="${1:-}"
case "$MODE" in
build|check|fmt|list|vet|eval|export)
shift
"cmd_$MODE" "$@"
;;
*)
usage
;;
esac