-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshellcheck.sh
More file actions
executable file
·73 lines (65 loc) · 2.09 KB
/
shellcheck.sh
File metadata and controls
executable file
·73 lines (65 loc) · 2.09 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
#!/bin/bash
wait_for_user='true'
verbose='true'
while getopts 'h?yq' opt; do
case "$opt" in
h|\?)
echo "usage: $0 [-y] [-q]"
exit 0
;;
y)
wait_for_user='false'
;;
q)
verbose='false'
;;
esac
done
shift $((OPTIND-1))
script=$(mktemp)
errors_found=0
for spellbook in "${@}"
do
echo $spellbook
array_length=$( yq e ".spells | length - 1" "$spellbook" )
if [ "$array_length" -lt 0 ] ; then
echo "Warning: Empty spell file $spellbook"
else
for element_index in $( seq 0 "$array_length" );do
spell="$( yq e ".spells[$element_index].match" "$spellbook" )"
echo '# shellcheck disable=2034' > "$script"
spellbook_dir="$(dirname "$(realpath "$spellbook")")"
echo "GANDALF_SPELLBOOK_DIR=${spellbook_dir}" >> "$script"
yq e ".spells[$element_index].inputs[] | \"INPUT_\(.name)=foo\"" "$spellbook" | grep -v "INPUT_=foo" >> "$script"
echo "$spell" | grep -oP '\?P<(.+?)>' | sed -nE 's#\?P<(.+)>#MATCH_\1=bar#p' >> "$script"
yq e ".spells[$element_index].run" "$spellbook" >> "$script"
if $verbose
then
echo "###################################"
echo "### FILE: $spellbook"
echo "### INDEX: $element_index"
echo "### SPELL: $spell"
echo "###################################"
fi
shellcheck -xP "${spellbook_dir}" -s bash "$script" -e 2129 -e 2002
ret=$?
errors_found="$(( errors_found + ret ))"
if (( ret != 0 )) && ! $verbose
then
echo
echo " ^^^ Above errors found in $spellbook, spell $element_index: '$spell'"
fi
if $wait_for_user
then
read -rn 1 -p "Press any key to continue ... "
fi
if $verbose || (( ret != 0 ))
then
echo
echo
fi
done
fi
done
rm "$script"
exit $errors_found