v1.2.0 added colour output; fixed parameter bugs; docs corrected

This commit is contained in:
Benjamin Winter 2024-02-27 16:35:29 +01:00
parent a3eb327e5b
commit 17f8f66a9b

View File

@ -11,13 +11,14 @@ set -eu
readonly PROGNAME=`/usr/bin/basename $0`
readonly PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
readonly REVISION="1.1.0"
readonly REVISION="1.2.0"
repo=""
login_old=""
login_new=""
dry_run=true
wait_time=0.25
use_colour=true
#
# FUNCTIONS
@ -68,12 +69,16 @@ INSTALLATION AND PREPARATION
- tea login add --name NEW --url https://newgitea.example.com --token 123459789123456789
USAGE
SWITCHES
-h | --help print this help
-c | --colour disable colour output
--GO stop dry mode
PARAMETERS
-r | --repo required, i.e. "my_organisation/my_repository"
-o | --login_old required, tea-id of your old login
-n | --login_new required, tea-id of your new login
-w | --wait wait time in s between issue handling (default 0.25)
--GO stop dry mode
EOF
}
@ -94,7 +99,7 @@ checkCommand()
# PARAMETERS
#
if [[ "$@" == "" ]] ; then error_in_or_out_not_specified ; fi
readonly TEMP=$(getopt -o h,r:o:n:w: --long help,GO,repo:login_old:,login_new:wait: -n "${PROGNAME}" -- "$@")
readonly TEMP=$(getopt -o h,r:o:n:w:c --long help,GO,colour,repo:,login_old:,login_new:,wait: -n "${PROGNAME}" -- "$@")
eval set -- "${TEMP}"
while true ; do
case "$1" in
@ -102,6 +107,9 @@ while true ; do
print_help
exit 0
;;
--colour|-c)
use_colour=false
;;
--repo|-r)
repo="$2"
shift
@ -135,7 +143,14 @@ if [[ -z "$repo" || -z "$login_old" || -z "$login_new" ]] ; then error_in_or_out
#
# START
#
if $dry_run; then echo -e "###\n### DRY RUN - will not change anything\n###"; fi
if $dry_run; then
t="###\n### DRY RUN - will not change anything\n###"
if [ $use_colour = true ]; then
echo -e "\e[1m\e[38;5;214m$t\e[0m"
else
echo -e "$t"
fi
fi
# check commands
checkCommand tea
@ -182,14 +197,35 @@ while IFS="¬"; read -r index author assignees; do
if [ $dry_run = false ]; then
tea issue edit --login "$login_new" --repo "$repo" --add-assignees "$assignees" "$index" >/dev/null
fi
echo " → OK"
t="OK"
if [ $use_colour = true ]; then
echo -e " → \e[1m\e[48;5;22m$t\e[0m"
else
echo "$t"
fi
else
echo " → INFO: added comment, no assignee"
t="INFO: added comment, no assignee"
if [ $use_colour = true ]; then
echo -e " → \e[1m\e[48;5;172m$t\e[0m"
else
echo -e "$t"
fi
fi
sleep $wait_time
done< <(echo "$json_old" | jq --raw-output '.[] | "\(.index)¬\(.author)¬\(.assignees)"')
if $dry_run; then
t="###\n### DRY RUN - nothing changed\n###"
if [ $use_colour = true ]; then
echo -e "\e[1m\e[38;5;214m$t\e[0m"
else
echo -e "$t"
fi
fi
echo "# done"
exit 0