From: gggeek Date: Sat, 11 Feb 2023 16:26:36 +0000 (+0000) Subject: add cmd to set up git hook X-Git-Tag: 4.10.0~2 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=957adb09db91555877570aca076b57719072fd01;p=plcapi.git add cmd to set up git hook --- diff --git a/NEWS.md b/NEWS.md index 1b02b87c..6b425286 100644 --- a/NEWS.md +++ b/NEWS.md @@ -159,6 +159,8 @@ * improved: added an example Symfony Client and Server to the demo files (using Symfony 6 / PHP 8 syntax) +* improved: added to the `taskfile` command an option to automatically set up the git hooks for development + * improved: made sure the test container and gha test runners have at least one locale with comma as decimal separator * BC notes: diff --git a/taskfile b/taskfile index 4ac0b871..a90efb6d 100755 --- a/taskfile +++ b/taskfile @@ -4,6 +4,7 @@ set -e # @todo test all commands on mac, windows-wsl. If there are issues, rewrite this in (plain, no dependencies) php or make it a polyglot? +# download the demo files and unzip them in the 'demo' folder function download_demos() { # @todo check for presence of curl, tar, grep, sed and tr first # NB: we always get the demos matching the current version, not the last one available @@ -14,12 +15,14 @@ function download_demos() { rm demofiles.tgz } +# remove the 'demo' folder function remove_demos() { ROOT_DIR="$(pwd)" if [ -d "${ROOT_DIR}/demo" ]; then rm -rf "${ROOT_DIR}/demo"; fi } # @todo can we find a better name than this? +# download and install the visual-editing component into the debugger function setup_debugger_visualeditor() { ROOT_DIR="$(pwd)" cd "${TMPDIR-/tmp}" @@ -38,11 +41,13 @@ function setup_debugger_visualeditor() { rm -rf jsxmlrpc* } +# remove the visual-editing component from the debugger function remove_debugger_visualeditor() { ROOT_DIR="$(pwd)" if [ -d "${ROOT_DIR}/debugger/jsxmlrpc" ]; then rm -rf "${ROOT_DIR}/debugger/jsxmlrpc"; fi } +# arg: $TAG. Replaces the lib version tag in all files (soutrce and docs) known to use it function tag_code() { TAG="$1" if [ -z "${TAG}" ]; then @@ -56,10 +61,39 @@ function tag_code() { sed -i -e "1s|.*|## XML-RPC for PHP version $TAG - $DATE|" NEWS.md } +# install the git hooks useful for development of this library +function setup_git_hooks() { + if [ -f "$(pwd)/.git/hooks/pre-push" ]; then + echo "ERROR: git pre-push hook already exists. Please check and remove file $(pwd)/.git/hooks/pre-push" >&2 + exit 1 + else + ln -s "$(pwd)/.githooks/pre-push.sh" "$(pwd)/.git/hooks/pre-push" + fi +} + +# prints this help text function help() { + # @todo allow a tag such as `# @internal` to denote functions as not available for external execution + declare -A DESCRIPTIONS + local CMD MAX LEN echo "$0 " echo "Tasks:" - compgen -A function | cat -n + MAX=-1 + for CMD in $(compgen -A function); do + LEN=${#CMD} + ((LEN > MAX)) && MAX=$LEN + DESCRIPTIONS[$CMD]=$(grep "function $CMD(" -B 1 "${BASH_SOURCE[0]}" | grep '^#' | grep -v '@todo' | sed 's/^# *//') + done + MAX=$((MAX + 4)) + for CMD in $(compgen -A function); do + if [ -z "${DESCRIPTIONS[$CMD]}" ]; then + echo " ${CMD}" + else + printf "%-${MAX}s %s\n" " ${CMD}" "${DESCRIPTIONS[$CMD]}" + #echo " ${CMD}: ${DESCRIPTIONS[$CMD]}" + fi + + done } if [ $# -eq 0 ]; then