Files
Odoo-Build/templates/task
T

89 lines
2.0 KiB
Bash
Executable File

#!/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
COLUMN="| %-${CMD_WIDTH}s | %-${OPT_WIDTH}s | %-${DESC_WIDTH}s |\n"
# Print table header
printf "$COLUMN" "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 "$COLUMN" "all" "" "Run all tasks."
printf "$COLUMN" "install" "" "Setup the local environment."
printf "$COLUMN" "lint" "" "Run pre-commit."
printf "$COLUMN" "docs" "" "Update index.html."
printf "$COLUMN" "source" "" "Source the Python virtual env."
printf "$COLUMN" "version" "" "Show version of required tools."
}
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 docs() {
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