-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun
executable file
·58 lines (47 loc) · 1.08 KB
/
run
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
#!/usr/bin/env bash
# Define your tasks here.
lint() {
_check_binaries "shellcheck"
find . -type f -iname "*.sh" -o -iname "*.bash" -not -path "./test/helpers*" -exec sh -c "shellcheck --format=tty --shell=bash {}" ";"
}
test() {
_check_binaries "bats"
find . -type f -iname "*.bats" -not -path "./test/helpers*" -exec sh -c "bats {}" ";"
}
format() {
_check_binaries "shfmt"
find . -type f -iname "*.sh" -o -iname "*.bash" -not -path "./test/helpers*" -exec sh -c "shfmt -bn -ci -w {}" ";"
}
watch() {
_check_binaries "entr"
find . -type f -iname "*.sh" -o -iname "*.bash" -o -iname "*.bats" -not -path "./test/helpers*" | entr -c bash run check
}
install() {
git submodule update --init --recursive
}
check() {
lint
test
}
# Don't go down here.
set -e
# Check binaries.
_check_binaries() {
for i in "$@"; do
[ -x "$(command -v "$i")" ] || {
echo "bats is required" >&2
exit 1
}
done
}
# Check for task.
[ -n "$1" ] || {
echo "first argument is mandatory" >&2
exit 1
}
[ -n "$(declare -f -F $1)" ] || {
echo "task unrecognized" >&2
exit 1
}
# Run task.
eval "$@"