-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathtask
executable file
·90 lines (75 loc) · 2.25 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
84
85
86
87
88
89
90
#!/bin/bash
set -e
if [[ -a ".env" ]]; then
source .env
fi
function help() {
echo
echo "task <command> [options]"
echo
echo "commands:"
echo
# Define column widths
cmd_width=10
opt_width=6
desc_width=40
# 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" "install" "" "Setup the local environment."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "lint" "" "Run pre-commit."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "doc" "" "Updte index.html."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "source" "" "Source the Python virtual env."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "version" "" "Show version of required tools."
echo
}
function version() {
uv --version
}
function install() {
echo "Setup venv and install python dependencies"
uv venv env
source env/bin/activate
uv 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
}
function doc() {
source env/bin/activate
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
}
if declare -f "$1" > /dev/null; then
"$1" "${@:2}"
else
case "$1" in
help)
help task
exit 1
;;
all)
install
lint
doc
;;
source)
source env/bin/activate
;;
*)
echo "Unknown command: $1"
help task
exit 1
;;
esac
fi