TT#140851 reorder_tests_tt2.sh with usage() and new functionalities

Implemented usage() function inside reorder_tests_tt2.sh to describe how to use it.
Additionally, 2 new options have been implemented:
- -m git|mv : if set the renaming is performed with "mv" command rather than "git mv", useful if you are not on a git directory
- -t : just outputs the renaming to stdout without really renaming (dry run)

Change-Id: I0be8a2d6468b66d365ec138a09e5ac5873bf694f
mr10.4
Alessio Garzi 4 years ago
parent 188e452e4a
commit 1fafd72736

@ -11,12 +11,63 @@ log_info()
echo "INFO: $*" echo "INFO: $*"
} }
function usage
{
echo "Usage: reorder_tests_tt2.sh [-t] [-m git|mv] firstmessagenumber [displacement]"
echo "Options:"
echo -e "\th: this help"
echo -e "\tm [git|mv]: select whether to use 'git move' or 'mv' while renaming"
echo -e "\tt: dry run"
echo "Args:"
echo -e "\\tfirstmessagenumber: numer of the first testfile to be processed"
echo -e "\\tdisplacement: displacement to add to the test filename (optional, considering 1 if not given)"
echo
echo "Examples:"
echo -e "\\t\$ reorder_tests_tt2.sh 19 2"
echo -e "\\t will take each testfile of the current directory with filename number >= 19 ( for example 0024_test.yml.tt2) and add 2"
echo -e "\\t this script will rename the files like this:"
echo -e "\\t ./0024_test.yml.tt2 -> ./0026_test.yml.tt2"
echo -e "\\t ./0023_test.yml.tt2 -> ./0025_test.yml.tt2"
echo -e "\\t ./0022_test.yml.tt2 -> ./0024_test.yml.tt2 "
echo -e "\\t ... and so on until we reach ./0019_test.yml.tt2"
echo -e "\\t"
echo -e "\\t\$ reorder_tests_tt2.sh -m mv 19 2"
echo -e "\\t this comand will do the same but it will use mv rather than git mv"
echo -e "\\t\$ reorder_tests_tt2.sh -t 19 2"
echo -e "\\t this comand will do the same but it will just preview what will be renamed and how without changing anything"
}
DRY_RUN=0
MODE="git"
while getopts 'hm:t' opt; do
case $opt in
t) DRY_RUN=1;;
m) MODE=${OPTARG};;
*) usage; exit 1;;
esac
done
shift $((OPTIND - 1))
INI=$1 INI=$1
DISP=${2:-1} DISP=${2:-1}
case $# in case $# in
1|2) ;; 1|2) ;;
*) echo "Wrong number or arguments"; usage; exit 1;; *) echo "Wrong number or argument s $#"; usage; exit 1;;
esac
if [[ "$DRY_RUN" == 1 ]]; then
echo "Using dryrun"
fi
case "${MODE}" in
mv) echo "Using ${MODE} for renaming";;
git) MODE="git mv"; echo "Using ${MODE} for renaming";;
*) echo "Error: mode ${MODE} unknown"
usage
exit 2;;
esac esac
last_file=$(printf "%04d_test.yml.tt2" "${INI}") last_file=$(printf "%04d_test.yml.tt2" "${INI}")
@ -34,8 +85,12 @@ find . -name '0*_test.yml.tt2' | sort -r | while read -r tfile ; do
if [ -f "${next_file}" ] ; then if [ -f "${next_file}" ] ; then
die "file ${next_file} already exist" die "file ${next_file} already exist"
fi fi
git mv "${tfile}" "${next_file}" if [[ "$DRY_RUN" == 1 ]]; then
echo " rename ${tfile} into ${next_file}"
else
"${MODE}" "${tfile}" "${next_file}"
log_info "OK ${num} => $next" log_info "OK ${num} => $next"
fi
else else
log_info "nothing to do with ${tfile}" log_info "nothing to do with ${tfile}"
fi fi

Loading…
Cancel
Save