Merge pull request #1052 from YunoHost/detect-wrong-arguments

[fix] detect misformated arguments in getopts
This commit is contained in:
Alexandre Aubin 2020-09-16 17:17:18 +02:00 committed by GitHub
commit 8bd1758c8c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -130,6 +130,12 @@ ynh_handle_getopts_args () {
then
# Remove the option and the space, so keep only the value itself.
all_args[0]="${all_args[0]#-${parameter} }"
# At this point, if all_args[0] start with "-", then the argument is not well formed
if [ "${all_args[0]:0:1}" == "-" ]
then
ynh_die --message="Argument \"${all_args[0]}\" not valid! Did you use a single \"-\" instead of two?"
fi
# Reduce the value of shift, because the option has been removed manually
shift_value=$(( shift_value - 1 ))
fi