chore: Enforce minimum clang-format version

main
Sean McBride 4 years ago
parent bf35467bf8
commit d51fe49c14

@ -1,29 +1,31 @@
#!/bin/bash #!/bin/bash
utility="clang-format" validate() {
utility_version="$("$utility" --version 2>/dev/null)" || { utility="clang-format"
utility_version="$("$utility" --version 2>/dev/null)" || {
echo "$utility not found in path!" echo "$utility not found in path!"
exit 1 exit 1
} }
regex="version ([0-9]+).([0-9]+).([0-9]+)" regex="version ([0-9]+).([0-9]+).([0-9]+)"
declare -i major=0 declare -i major=0
declare -i minor=0 declare -i minor=0
declare -i patch=0 declare -i patch=0
declare -i required_major=9 declare -i required_major=9
declare -i required_minor=0 declare -i required_minor=0
declare -i required_patch=0 declare -i required_patch=0
if [[ "$utility_version" =~ $regex ]]; then if [[ "$utility_version" =~ $regex ]]; then
major="${BASH_REMATCH[1]}" major="${BASH_REMATCH[1]}"
minor="${BASH_REMATCH[2]}" minor="${BASH_REMATCH[2]}"
patch="${BASH_REMATCH[3]}" patch="${BASH_REMATCH[3]}"
fi fi
if ((major < required_major)) || ((minor < required_minor)) || ((patch < required_patch)); then if ((major < required_major)) || ((minor < required_minor)) || ((patch < required_patch)); then
echo "$utility $required_major.$required_minor.$required_patch required, but is $major.$minor.$patch" echo "$utility $required_major.$required_minor.$required_patch required, but is $major.$minor.$patch"
exit 1 exit 1
fi fi
}
help() { help() {
echo "Usage: $0 [OPTION]..." echo "Usage: $0 [OPTION]..."
@ -52,7 +54,7 @@ format() {
} }
case $1 in case $1 in
"-h" | "--help") help ;; "-h" | "--help") help ;;
"-d" | "--dry-run") dry_run ;; "-d" | "--dry-run") validate && dry_run ;;
"") format ;; "") validate && format ;;
esac esac

Loading…
Cancel
Save