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