-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvalidate_vars_map.sh
More file actions
29 lines (27 loc) · 1.04 KB
/
validate_vars_map.sh
File metadata and controls
29 lines (27 loc) · 1.04 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
function validate_vars_map() {
local -n referenced_map="$1"
local prompt="$2"
# Validate: ensure all placeholders in prompt are in referenced_map
for tmpl in $(grep -oP '<__[^>]+__>' <<<"$prompt" | sort -u); do
if [[ -z "${referenced_map[$tmpl]+_}" ]]; then
echo "Error: custom template string '$tmpl' was found in the prompt file, but is not present in the variables file." >&2
return 1
fi
done
# Validate: ensure all keys in referenced_map exist in prompt
for key in "${!referenced_map[@]}"; do
if [[ "$key" == "<__INSTRUCTIONS__>" ]]; then
# This key is optional
continue
fi
if ! grep -q "$key" <<<"$prompt"; then
if [[ "$key" == "<__RESPONSE_FORMAT_REQUIREMENTS__>" || "$key" == "<__GIT_DIFF__>" ]]; then
# This key is mandatory
echo "Error: key '$key' is essential for cfme to function, but not present in the prompt." >&2
return 1
fi
echo "Error: custom key '$key' was found in variables, but not present in the prompt." >&2
return 1
fi
done
}