autohelp en version courte

This commit is contained in:
Jephté Clain 2023-10-20 10:49:41 +04:00
parent 6e088c51a2
commit 19ca7cfbd3
1 changed files with 12 additions and 5 deletions

View File

@ -115,7 +115,7 @@ function parse_args() {
[ "${1#-}" == "$1" ] && { __USAGE="$1"; shift; } [ "${1#-}" == "$1" ] && { __USAGE="$1"; shift; }
if [ -n "$__r" ]; then if [ -n "$__r" ]; then
: :
elif [ "$1" != "+" -a "${1#-}" == "$1" ]; then elif [ $# -gt 0 -a "$1" != "+" -a "${1#-}" == "$1" ]; then
eerror "Invalid args definition: third arg must be an option" eerror "Invalid args definition: third arg must be an option"
__r=1 __r=1
else else
@ -171,7 +171,12 @@ function __parse_args() {
# sauter la description le cas échéant # sauter la description le cas échéant
[ "${1#-}" == "$1" ] && shift [ "${1#-}" == "$1" ] && shift
done done
# __sopts ne doit pas être vide, rajouter ? si aucune option courte n'est
# définie, indépendamment de la valeur de autohelp
[ -n "$__autohelp" ] && __lopts="$__lopts${__lopts:+,}help" [ -n "$__autohelp" ] && __lopts="$__lopts${__lopts:+,}help"
[ -n "$__sopts" ] || __sopts=?
__sopts="$__popt$__sopts" __sopts="$__popt$__sopts"
local -a __getopt_args local -a __getopt_args
__getopt_args=(-n "$MYNAME" ${__sopts:+-o "$__sopts"} ${__lopts:+-l "$__lopts"} -- "${__ARGS[@]}") __getopt_args=(-n "$MYNAME" ${__sopts:+-o "$__sopts"} ${__lopts:+-l "$__lopts"} -- "${__ARGS[@]}")
@ -382,10 +387,12 @@ function __parse_opt() {
[ -n "$__found" ] && return 0 [ -n "$__found" ] && return 0
done done
# ici, l'option n'a pas été trouvée, on ne devrait pas arriver ici if [ -n "$__autohelp" ]; then
if [ "$option_" == --help -a -n "$__autohelp" ]; then if [ "$option_" == --help -o "$option" == -? ]; then
__action="showhelp@" __action="showhelp@"
return 0 return 0
fi
fi fi
# ici, l'option n'a pas été trouvée, on ne devrait pas arriver ici
eerror "Unexpected option '$option_'"; eval "$__DIE" eerror "Unexpected option '$option_'"; eval "$__DIE"
} }