From af332ea961d03f00c9e4acae129d5b44be5ba0d9 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Sat, 4 Nov 2023 00:59:42 +0400 Subject: [PATCH] modifs.mineures sans commentaires --- bash/src/base.args.sh | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/bash/src/base.args.sh b/bash/src/base.args.sh index be4c313..5638082 100644 --- a/bash/src/base.args.sh +++ b/bash/src/base.args.sh @@ -44,6 +44,9 @@ usage USAGE \$MYNAME [options] FILE ~~~ + Peut contenir autant de lignes que nécessaire. Chaque ligne est préfixée du + nom du script, jusqu'à la première ligne vide. Ensuite, les lignes sont + affichées telles quelles. +|- : méthode d'analyse des arguments. @@ -236,21 +239,33 @@ function __parse_args() { help="$help: $__DESC" fi + local first usage nl=$'\n' local prefix=" $MYNAME " - local -a usages; local usage="$__USAGE" - [ -n "$usage" ] || usage="[options]" - IFS=$'\n' read -a usages -d "" <<<"$usage" + local usages="$__USAGE" + [ -n "$usages" ] || usages="[options]" help="$help USAGE" - for usage in "${usages[@]}"; do - [ -n "$usage" ] || continue + first=1 + while [ -n "$usages" ]; do + usage="${usages%%$nl*}" + if [ "$usage" != "$usages" ]; then + usages="${usages#*$nl}" + else + usages= + fi + if [ -n "$first" ]; then + first= + [ -z "$usage" ] && continue + else + [ -z "$usage" ] && prefix= + fi help="$help $prefix$usage" done set -- "${__DEFS[@]}" - local first=1 + first=1 while [ $# -gt 0 ]; do case "$1" in +) shift; continue;;