Process command-line arguments
# Constants
VERSION="0.1.0"
# Options vars
debug=0
verbose=0
quiet=0
usage() {
msg=$1
if [ -n "${msg}" ]; then
printf "%s\n" "${msg}"
fi
cat <<EOF
Usage: check-gen [option] ... [directory] ...
Options:
-h, --help Show this message and quit
-d, --debug Output debugging messages
-q, --quiet Only output fatal error messages
-v, --verbose Be verbose (show external command output)
--version Print version and exit
Arguments:
directory Path to project source
EOF
}
# Parse args
while [ ${#} -gt 0 ]
do
a=${1}
shift
case "${a}" in
-h|--help)
usage
exit 0
;;
-d|--debug)
debug=1
;;
-q|--quiet)
if [ ${verbose} = 1 ]; then
usage "The --quiet and --verbose options are mutually exclusive"
exit 1
fi
quiet=1
;;
-v|--verbose)
if [ ${quiet} = 1 ]; then
usage "The --quiet and --verbose options are mutually exclusive"
exit 1
fi
verbose=1
;;
--version)
echo "Check generator version ${VERSION}"
exit 0
;;
-*)
usage "You have specified an invalid option: ${a}"
exit 1
;;
*)
profile=$a
;;
esac
done
Source: https://gitlab.com/oxr463/quickstart/-/blob/master/src/quickstart.sh#L59
Edited by Lucas Ramage