autodebug et autohelp
This commit is contained in:
parent
a02d25f8d1
commit
bc14f4b4ca
|
@ -154,7 +154,8 @@ function parse_args() {
|
||||||
}
|
}
|
||||||
function __parse_args() {
|
function __parse_args() {
|
||||||
## tout d'abord, construire la liste des options
|
## tout d'abord, construire la liste des options
|
||||||
local __AUTOHELP=1 # faut-il gérer automatiquement l'affichage de l'aide?
|
local __AUTOH=1 __AUTOHELP=1 # faut-il gérer automatiquement l'affichage de l'aide?
|
||||||
|
local __AUTOD=1 __AUTODEBUG=1 # faut-il rajouter les options -D et --debug
|
||||||
local __ADVHELP # y a-t-il des options avancées?
|
local __ADVHELP # y a-t-il des options avancées?
|
||||||
local __popt __sopts __lopts
|
local __popt __sopts __lopts
|
||||||
local -a __defs
|
local -a __defs
|
||||||
|
@ -187,12 +188,15 @@ function __parse_args() {
|
||||||
# -o
|
# -o
|
||||||
__def="${__def#-}"
|
__def="${__def#-}"
|
||||||
__sopts="$__sopts$__def$__witharg"
|
__sopts="$__sopts$__def$__witharg"
|
||||||
|
[ "$__def" == h ] && __AUTOH=
|
||||||
|
[ "$__def" == D ] && __AUTOD=
|
||||||
else
|
else
|
||||||
# -longopt ou longopt
|
# -longopt ou longopt
|
||||||
__def="${__def#-}"
|
__def="${__def#-}"
|
||||||
__lopts="$__lopts${__lopts:+,}$__def$__witharg"
|
__lopts="$__lopts${__lopts:+,}$__def$__witharg"
|
||||||
fi
|
fi
|
||||||
[ "$__def" == help -o "$__def" == help++ ] && __AUTOHELP=
|
[ "$__def" == help -o "$__def" == help++ ] && __AUTOHELP=
|
||||||
|
[ "$__def" == debug ] && __AUTODEBUG=
|
||||||
done
|
done
|
||||||
# sauter l'action
|
# sauter l'action
|
||||||
shift
|
shift
|
||||||
|
@ -203,10 +207,10 @@ function __parse_args() {
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# __sopts ne doit pas être vide, rajouter ? si aucune option courte n'est
|
[ -n "$__AUTOH" ] && __sopts="${__sopts}h"
|
||||||
# définie, indépendamment de la valeur de autohelp
|
|
||||||
[ -n "$__AUTOHELP" ] && __lopts="$__lopts${__lopts:+,}help,help++"
|
[ -n "$__AUTOHELP" ] && __lopts="$__lopts${__lopts:+,}help,help++"
|
||||||
[ -n "$__sopts" ] || __sopts=?
|
[ -n "$__AUTOD" ] && __sopts="${__sopts}D"
|
||||||
|
[ -n "$__AUTODEBUG" ] && __lopts="$__lopts${__lopts:+,}debug"
|
||||||
|
|
||||||
__sopts="$__popt$__sopts"
|
__sopts="$__popt$__sopts"
|
||||||
local -a __getopt_args
|
local -a __getopt_args
|
||||||
|
@ -456,8 +460,12 @@ function __parse_opt() {
|
||||||
|
|
||||||
[ -n "$__found" ] && return 0
|
[ -n "$__found" ] && return 0
|
||||||
done
|
done
|
||||||
|
if [ -n "$__AUTOH" -a "$option_" == -h ]; then
|
||||||
|
__action="showhelp@"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
if [ -n "$__AUTOHELP" ]; then
|
if [ -n "$__AUTOHELP" ]; then
|
||||||
if [ "$option_" == --help -o "$option" == -? ]; then
|
if [ "$option_" == --help ]; then
|
||||||
__action="showhelp@"
|
__action="showhelp@"
|
||||||
return 0
|
return 0
|
||||||
elif [ "$option_" == --help++ ]; then
|
elif [ "$option_" == --help++ ]; then
|
||||||
|
@ -465,6 +473,14 @@ function __parse_opt() {
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
if [ -n "$__AUTOD" -a "$option_" == -D ]; then
|
||||||
|
__action=set_debug
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
if [ -n "$__AUTODEBUG" -a "$option_" == --debug ]; then
|
||||||
|
__action=set_debug
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
# ici, l'option n'a pas été trouvée, on ne devrait pas arriver ici
|
# 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"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
#@include "base.tools.awk"
|
|
||||||
BEGIN {
|
|
||||||
PROFILES[0] = 0; delete PROFILES
|
|
||||||
PROFILES[0] = "prod"
|
|
||||||
PROFILES[1] = "test"
|
|
||||||
HOSTS[0] = 0; delete HOSTS
|
|
||||||
HOSTS[0] = "first"
|
|
||||||
HOSTS[1] = "second"
|
|
||||||
VALUES[0] = 0; delete VALUES
|
|
||||||
}
|
|
||||||
{ if (should_generate_password()) { generate_password() } }
|
|
||||||
/\#@@EACH:PROFILES@@/ {
|
|
||||||
sub(/\#@@EACH:PROFILES@@/, "")
|
|
||||||
for (index in PROFILES) {
|
|
||||||
print gensub(/@@PROFILE@@/, PROFILES[index], "g")
|
|
||||||
}
|
|
||||||
next
|
|
||||||
}
|
|
||||||
/\#@@EACH:HOSTS@@/ {
|
|
||||||
sub(/\#@@EACH:HOSTS@@/, "")
|
|
||||||
for (index in HOSTS) {
|
|
||||||
print gensub(/@@HOST@@/, HOSTS[index], "g")
|
|
||||||
}
|
|
||||||
next
|
|
||||||
}
|
|
||||||
/\#@@EACH:VALUES@@/ {
|
|
||||||
sub(/\#@@EACH:VALUES@@/, "")
|
|
||||||
next
|
|
||||||
}
|
|
||||||
{ print }
|
|
Loading…
Reference in New Issue