Ensure arguments have expected values

This commit is contained in:
Jeremy Gardais 2020-02-27 16:04:49 +01:00
parent fafd2cfc20
commit cf12d2bcd9
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 32 additions and 19 deletions

View File

@ -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,16 +59,16 @@ 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
## ]]]
## Manage arguments [[[
case "${_nb_arg}" in
0 )
## Set test to run to default (short)
test_to_run="short"
@ -69,9 +81,10 @@ case "${_nb_arg}" in
print_help_message
exit 2
;;
esac
# ]]]
esac
## ]]]
## Verify the content of arguments
check_arguments
}
## ]]]
## Test if a disk really support SMART [[[