-
Notifications
You must be signed in to change notification settings - Fork 12
/
sanity.sh
executable file
·69 lines (54 loc) · 1.38 KB
/
sanity.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
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
#!/usr/bin/env bash
set -eu
set -o pipefail
readonly PROGDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=SCRIPTDIR/.util/print.sh
source "${PROGDIR}/.util/print.sh"
function sanity::check() {
local dir
dir="${1}"
shift 1
while [[ "${#}" != 0 ]]; do
case "${1}" in
--help|-h)
shift 1
usage
exit 0
;;
"")
# skip if the argument is empty
shift 1
;;
*)
util::print::error "unknown argument \"${1}\""
esac
done
sanity::check::rule::directories "${dir}"
}
function usage() {
cat <<-USAGE
sanity.sh [OPTIONS]
Checks if the contents of builder/ implementation/ language-family/ and stack/
follow rules.
OPTIONS
--help -h prints the command usage
USAGE
}
# Rule: all children of implemenation/ & language-family/ must be directories
function sanity::check::rule::directories() {
local dir
dir="${1}"
for cnbdir in 'builder' 'implementation' 'language-family' 'stack' ; do
if [[ ! -d "${dir}/${cnbdir}" ]]; then
echo "${cnbdir} dir not found"
exit 1
fi
if [[ -n "$(find "${dir}/${cnbdir}" -maxdepth 1 \! -type d)" ]]; then
echo "All files in ${cnbdir}/ must be directories. Exiting."
exit 1
fi
done
}
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
sanity::check "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" "${@:-}"
fi