From cf12d2bcd9d2ce50b51672822ea1d2016ac7339c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Thu, 27 Feb 2020 16:04:49 +0100 Subject: [PATCH] Ensure arguments have expected values --- smart.run.test.sh | 51 +++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/smart.run.test.sh b/smart.run.test.sh index dbddc87..d53117c 100755 --- a/smart.run.test.sh +++ b/smart.run.test.sh @@ -40,6 +40,18 @@ EXAMPLE : HELP } ## ]]] +## Check arguments [[[ +## Ensure arguments have the expected value +check_arguments() { + if ! printf -- '%s' "${test_to_run}" | grep -q -E -- "(short|long)"; then + printf "${c_redb}%-6b${c_reset}\n" "ERROR : Can't manage '${test_to_run}' test type." + + print_help_message + + exit 3 + fi +} +## ]]] ## Manage the arguments [[[ manage_arguments() { _nb_arg="${#}" @@ -47,31 +59,32 @@ manage_arguments() { [ "${debug}" -eq "0" ] && printf "${c_magentab}%-6b${c_reset}\n" "DEBUG : manage_arguments func − ${_nb_arg} argument(s) to manage. List:\n ${_all_args}" -## If help is needed [[[ + ## If help is needed [[[ if printf -- '%s' "${_all_args}" | grep -q -E -- "-h|--help|help"; then print_help_message exit 0 fi -## ]]] -# Manage arguments [[[ -case "${_nb_arg}" in - 0 ) - ## Set test to run to default (short) - test_to_run="short" - ;; - 1 ) - test_to_run="${1}" - ;; - * ) - ## More than managed number of arguments - print_help_message - exit 2 - ;; -esac -# ]]] - + ## ]]] + ## Manage arguments [[[ + case "${_nb_arg}" in + 0 ) + ## Set test to run to default (short) + test_to_run="short" + ;; + 1 ) + test_to_run="${1}" + ;; + * ) + ## More than managed number of arguments + print_help_message + exit 2 + ;; + esac + ## ]]] + ## Verify the content of arguments + check_arguments } ## ]]] ## Test if a disk really support SMART [[[