-
Notifications
You must be signed in to change notification settings - Fork 57
/
generate.sh
executable file
·31 lines (25 loc) · 973 Bytes
/
generate.sh
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
#!/bin/bash
DEFAULT_ERROR_CODES="0"
# First arg is the command
# Second arg is the string of acceptable error codes seperated by space. E.g. "0 1"
pre_commit_wrapper () {
echo "running pre-commit run --all-files --hook-stage=manual ${1}"
exec 5>&1
acceptable_errors=${2:-$DEFAULT_ERROR_CODES}
out=$(pre-commit run --all-files --hook-stage=manual "${1}" | tee >(cat - >&5))
exit_code=$( echo "$out" | grep -- "- exit code:" | cut -d":" -f2 | sed 's/[^0-9]*//g' )
if [[ -n $exit_code ]]; then
re="([^0-9]|^)$exit_code([^0-9]|$)"
if ! grep -qE "$re" <<< "$acceptable_errors" ; then
echo "pre-commit subcommand failed with error_code: $exit_code. See output above"
exit "$exit_code";
fi
fi
echo "command 'pre-commit run --all-files --hook-stage=manual ${1}' success"
}
rm -rf api/* examples/*
pre_commit_wrapper generator
pre_commit_wrapper examples
pre_commit_wrapper docs
pre_commit_wrapper generate-doc
pre_commit_wrapper lint