reworked command line reading

This commit is contained in:
levasseur
2021-09-08 17:20:43 +02:00
parent a4bafe03f5
commit bec63a5304

View File

@@ -17,7 +17,7 @@ read_commandline()
syntax_error()
{
prnt E "Erreur d'analyse de la ligne de commande, vérifiez vos paramètres."
die 1
die 1 --force
}
# Processing command line options
@@ -26,85 +26,82 @@ read_commandline()
local want_conffile=false
for opt in $@; do
if [[ $want_module != true ]] && [[ $want_logfile != true ]] &&
[[ $want_conffile != true ]]; then
case $opt in
"-h"|"--help")
disp_help
exit 0
;;
"-v"|"--version")
show_version
exit 0
;;
"-m"|"--module")
local want_module=true
;;
"-c"|"--check-only")
export CHECK_ONLY=true
;;
"-j"|"--jump")
export JUMP=true
;;
"-k"|"--keep-going")
export KEEPGOING=true
;;
"-r"|"--resume")
if [[ -s $STAGE_FILE ]]; then
export RESUME=true
case $opt in
"-h"|"--help")
disp_help
exit 0
;;
"-v"|"--version")
show_version
exit 0
;;
"-m"|"--module")
local want_module=true
;;
"-c"|"--check-only")
export CHECK_ONLY=true
;;
"-j"|"--jump")
export JUMP=true
;;
"-k"|"--keep-going")
export KEEPGOING=true
;;
"-r"|"--resume")
if [[ -s $STAGE_FILE ]]; then
export RESUME=true
else
prnt E "Le fichier d'état n'existe pas ou est vide !"
prnt E "Sans ce fichier, la reprise n'est pas possible."
die 1 --force
fi
;;
"-R"|"--no-root-check")
export NO_ROOT_CHECK=true
;;
"-l"|"--logfile")
local want_logfile=true
;;
"-f"|"--file")
local want_conffile=true
;;
*)
if [[ $want_module == true ]]; then
[[ $want_logfile == true ]] && synthax_error
[[ $want_conffile == true ]] && synthax_error
if [[ ! $MANUAL_MODULE_LIST ]]; then
export MANUAL_MODULE_LIST=$opt
want_module=false
else
prnt E "Le fichier d'état n'existe pas ou est vide !"
prnt E "Sans ce fichier, la reprise n'est pas possible."
prnt E "Une liste de module à déjà été fournie !"
prnt E "La ligne de commande ne tolère qu'un seul paramètre --module."
die 1 --force
fi
;;
"-R"|"--no-root-check")
export NO_ROOT_CHECK=true
;;
"-l"|"--logfile")
local want_logfile=true
;;
"-f"|"--file")
local want_conffile=true
;;
*)
prnt E "Paramètre \"$opt\" non géré."
die 1 --force
;;
esac
else
if [[ $want_module == true ]]; then
[[ $want_logfile == true ]] && synthax_error
[[ $want_conffile == true ]] && synthax_error
if [[ ! $MANUAL_MODULE_LIST ]]; then
export MANUAL_MODULE_LIST=$opt
want_module=false
else
prnt E "Une liste de module à déjà été fournie !"
prnt E "La ligne de commande ne tolère qu'un seul paramètre --module."
die 1 --force
fi
elif [[ $want_logfile == true ]]; then
[[ $want_module == true ]] && synthax_error
[[ $want_conffile == true ]] && synthax_error
if [[ ! $NEW_LOGFILE ]]; then
export NEW_LOGFILE=$opt
elif [[ $want_logfile == true ]]; then
[[ $want_module == true ]] && synthax_error
[[ $want_conffile == true ]] && synthax_error
if [[ ! $NEW_LOGFILE ]]; then
export NEW_LOGFILE=$opt
want_logfile=false
else
prnt E "Il n'est pas possible de spécifier plusieurs fichiers de log."
die 1 --force
fi
elif [[ $want_conffile == true ]]; then
[[ $want_module == true ]] && synthax_error
[[ $want_logfile == true ]] && synthax_error
export CONFFILES="$CONFFILES $opt"
want_logfile=false
else
prnt E "Il n'est pas possible de spécifier plusieurs fichiers de log."
prnt E "Paramètre \"$opt\" non géré."
die 1 --force
fi
elif [[ $want_conffile == true ]]; then
[[ $want_module == true ]] && synthax_error
[[ $want_logfile == true ]] && synthax_error
export CONFFILES="$CONFFILES $opt"
want_logfile=false
fi
fi
;;
esac
done
# If those var are true at that point, something is wrong
if [[ $want_logfile == true ]] || [[ $want_module == true ]]; then
if [[ $want_logfile == true ]] || [[ $want_module == true ]] || [[ $want_conffile == true ]]; then
syntax_error
fi
}