-
Notifications
You must be signed in to change notification settings - Fork 3
/
task
executable file
·83 lines (70 loc) · 1.87 KB
/
task
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
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
set -e
if [[ -a ".env" ]]; then
export $(cat .env | sed 's/^#.*//g' | xargs)
fi
function help() {
echo
echo "task <command> [options]"
echo
echo "commands:"
echo
# Define column widths
cmd_width=10
opt_width=6
desc_width=32
# Print table header
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "Command" "Option" "Description"
echo "|$(printf '%*s' $((cmd_width + 2)) '' | tr ' ' '-')|$(printf '%*s' $((opt_width + 2)) '' | tr ' ' '-')|$(printf '%*s' $((desc_width + 2)) '' | tr ' ' '-')|"
# Print table rows
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "all" "" "Run all tasks."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "version" "" "Show version of required tools."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "init" "" "Init local env."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "lint" "" "Run pre-commit and update index.html."
echo
}
function version() {
python3 -V
pip -V
}
function init() {
echo "Install python dependencies"
python3 -m venv env
source env/bin/activate
pip install pre-commit rst2html5
}
function lint() {
source env/bin/activate
echo "Run pre-commit"
pre-commit run --all-files # --show-diff-on-failure --color=always
echo "Update index.html for all modules"
for MODULE in ./*; do
if [ -f "$MODULE/README.rst" ]; then
cd "$MODULE" || exit
rst2html5 README.rst static/description/index.html
cd .. || exit
fi
done
}
case "$1" in
help)
help
;;
all)
version
init
lint
;;
version)
version
;;
init)
init
;;
lint)
lint
;;
*)
help
exit 1;
esac