Skip to content

Commit 957adb0

Browse files
committed
add cmd to set up git hook
1 parent 1149eec commit 957adb0

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@
159159

160160
* improved: added an example Symfony Client and Server to the demo files (using Symfony 6 / PHP 8 syntax)
161161

162+
* improved: added to the `taskfile` command an option to automatically set up the git hooks for development
163+
162164
* improved: made sure the test container and gha test runners have at least one locale with comma as decimal separator
163165

164166
* BC notes:

taskfile

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set -e
44

55
# @todo test all commands on mac, windows-wsl. If there are issues, rewrite this in (plain, no dependencies) php or make it a polyglot?
66

7+
# download the demo files and unzip them in the 'demo' folder
78
function download_demos() {
89
# @todo check for presence of curl, tar, grep, sed and tr first
910
# NB: we always get the demos matching the current version, not the last one available
@@ -14,12 +15,14 @@ function download_demos() {
1415
rm demofiles.tgz
1516
}
1617

18+
# remove the 'demo' folder
1719
function remove_demos() {
1820
ROOT_DIR="$(pwd)"
1921
if [ -d "${ROOT_DIR}/demo" ]; then rm -rf "${ROOT_DIR}/demo"; fi
2022
}
2123

2224
# @todo can we find a better name than this?
25+
# download and install the visual-editing component into the debugger
2326
function setup_debugger_visualeditor() {
2427
ROOT_DIR="$(pwd)"
2528
cd "${TMPDIR-/tmp}"
@@ -38,11 +41,13 @@ function setup_debugger_visualeditor() {
3841
rm -rf jsxmlrpc*
3942
}
4043

44+
# remove the visual-editing component from the debugger
4145
function remove_debugger_visualeditor() {
4246
ROOT_DIR="$(pwd)"
4347
if [ -d "${ROOT_DIR}/debugger/jsxmlrpc" ]; then rm -rf "${ROOT_DIR}/debugger/jsxmlrpc"; fi
4448
}
4549

50+
# arg: $TAG. Replaces the lib version tag in all files (soutrce and docs) known to use it
4651
function tag_code() {
4752
TAG="$1"
4853
if [ -z "${TAG}" ]; then
@@ -56,10 +61,39 @@ function tag_code() {
5661
sed -i -e "1s|.*|## XML-RPC for PHP version $TAG - $DATE|" NEWS.md
5762
}
5863

64+
# install the git hooks useful for development of this library
65+
function setup_git_hooks() {
66+
if [ -f "$(pwd)/.git/hooks/pre-push" ]; then
67+
echo "ERROR: git pre-push hook already exists. Please check and remove file $(pwd)/.git/hooks/pre-push" >&2
68+
exit 1
69+
else
70+
ln -s "$(pwd)/.githooks/pre-push.sh" "$(pwd)/.git/hooks/pre-push"
71+
fi
72+
}
73+
74+
# prints this help text
5975
function help() {
76+
# @todo allow a tag such as `# @internal` to denote functions as not available for external execution
77+
declare -A DESCRIPTIONS
78+
local CMD MAX LEN
6079
echo "$0 <task> <args>"
6180
echo "Tasks:"
62-
compgen -A function | cat -n
81+
MAX=-1
82+
for CMD in $(compgen -A function); do
83+
LEN=${#CMD}
84+
((LEN > MAX)) && MAX=$LEN
85+
DESCRIPTIONS[$CMD]=$(grep "function $CMD(" -B 1 "${BASH_SOURCE[0]}" | grep '^#' | grep -v '@todo' | sed 's/^# *//')
86+
done
87+
MAX=$((MAX + 4))
88+
for CMD in $(compgen -A function); do
89+
if [ -z "${DESCRIPTIONS[$CMD]}" ]; then
90+
echo " ${CMD}"
91+
else
92+
printf "%-${MAX}s %s\n" " ${CMD}" "${DESCRIPTIONS[$CMD]}"
93+
#echo " ${CMD}: ${DESCRIPTIONS[$CMD]}"
94+
fi
95+
96+
done
6397
}
6498

6599
if [ $# -eq 0 ]; then

0 commit comments

Comments
 (0)