reworked error management, added --logfile option, reworked command line analysing

This commit is contained in:
fatalerrors
2021-07-20 20:59:38 +02:00
parent 0a4029e60d
commit cf6c327c19
4 changed files with 100 additions and 86 deletions

View File

@@ -2,30 +2,32 @@
read_commandline()
{
# Processing command line options
want_module=false
local want_module=false
local want_logfile=false
for opt in $@; do
if [[ $want_module == false ]]; then
if [[ $want_module != true ]] && [[ $want_logfile != true ]]; then
case $opt in
"-h"|"--help")
disp_help
exit 0
;;
;;
"-v"|"--version")
show_version
exit 0
;;
;;
"-m"|"--module")
want_module=true
;;
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
@@ -34,28 +36,49 @@ read_commandline()
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
;;
*)
prnt E "Paramètre \'$opt\' non géré."
disp_help
exit 1
;;
prnt E "Paramètre \"$opt\" non géré."
die 1 --force
;;
esac
else
if [[ ! $MANUAL_MODULE_LIST ]]; then
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 paramètre --module."
die 1 --force
if [[ $want_module == true ]]; then
[[ $want_logfile == 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 paramètre --module."
die 1 --force
fi
elif [[ $want_logfile == true ]]; then
[[ $want_module == 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
fi
fi
done
# If those var are true at that point, something is wrong
if [[ $want_logfile == true ]] || [[ $want_module == true ]]; then
prnt E "Erreur de syntaxe dans la ligne de commande."
die 1
fi
}
export -f read_commandline
load_configuration()
{
@@ -73,14 +96,10 @@ load_configuration()
fi
fi
}
export -f load_configuration
process_commandline_and_vars()
{
if [[ $want_module == true ]]; then
prnt E "La liste des modules à exécuter est manquante !"
die 1 --force
fi
# Check unconsistant parameters
if [[ $CHECK_ONLY == true ]]; then
[[ $JUMP == true ]] && (
@@ -120,3 +139,4 @@ process_commandline_and_vars()
die 5
fi
}
export -f process_commandline_and_vars