0
0
Fork 0
mirror of https://github.com/schollz/croc.git synced 2025-10-11 13:21:00 +02:00

swapping getopt (which apparently is not good to use) for getopts in an attempt to make it more cross-platform without having to break out the logic based on OS...again...

This commit is contained in:
Micheal Quinn 2019-08-11 17:07:43 -05:00
parent d39266a36d
commit 9c6f01ca91
No known key found for this signature in database
GPG key ID: 0E7217F3C30BA059

View file

@ -49,11 +49,11 @@ print_help() {
help_header="croc Installer Script" help_header="croc Installer Script"
help_message="Usage: help_message="Usage:
-p, --prefix -p PREFIX
Prefix to install croc into. Directory must already exist. Prefix to install croc into. Directory must already exist.
Default = /usr/local/bin Default = /usr/local/bin
-h, --help -h
Prints this helpfull message and exit." Prints this helpfull message and exit."
echo "${help_header}" echo "${help_header}"
@ -568,21 +568,16 @@ main() {
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# ARGUMENT PARSING # ARGUMENT PARSING
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
OPTS=$(getopt -o hp: --long help,prefix: -n 'parse-options' -- "${@}") OPTS="hp:"
getopt_rcode="${?}" while getopts "${OPTS}" optchar; do
if [ ${getopt_rcode} != 0 ] ; then case "${optchar}" in
echo "Failed parsing options." >&2 'h' ) print_help
exit 1 exit 0
fi ;;
'p' ) PREFIX="${OPTARG}"
eval set -- "${OPTS}" ;;
'?' ) print_message "Unknown option ${OPTARG}" "warn"
while true; do ;;
case "${1}" in
-p | --prefix ) PREFIX="${2}"; shift 2;;
-h | --help ) print_help; exit 0;;
-- ) shift; break ;;
* ) break ;;
esac esac
done done