Added -h, --help option

This commit is contained in:
Jarno Rankinen 2020-08-01 10:24:49 +03:00
parent 187673cbd4
commit dec51cee76
1 changed files with 30 additions and 2 deletions

32
snapsh
View File

@ -19,14 +19,42 @@
help() { help() {
printf "Usage: printf "Usage:
snapsh [OPTIONS] snapsh [OPTIONS]
Options:
Options:
-h, --help Display this help message
Exit codes: Exit codes:
2 - Invalid arguments" 2 - Invalid options\n"
} }
# If no options are given, display help # If no options are given, display help
if [[ "$#" -eq 0 ]]; then if [[ "$#" -eq 0 ]]; then
help help
exit 2 exit 2
fi fi
# Options parsing:
OPTIONS=$(getopt -a -n snapsh -o h --long help -- "$@")
# Invalid options (getopt returns nonzero)
if [[ "$?" -ne 0 ]]; then
printf "Error Parsing options\n"
help
exit 2
fi
#eval set -- "$OPTIONS"
while true;
do
case "$1" in
-h | --help)
help
exit 0
;;
esac
done