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:
parent
d39266a36d
commit
9c6f01ca91
1 changed files with 12 additions and 17 deletions
|
@ -49,11 +49,11 @@ print_help() {
|
|||
|
||||
help_header="croc Installer Script"
|
||||
help_message="Usage:
|
||||
-p, --prefix
|
||||
-p PREFIX
|
||||
Prefix to install croc into. Directory must already exist.
|
||||
Default = /usr/local/bin
|
||||
|
||||
-h, --help
|
||||
-h
|
||||
Prints this helpfull message and exit."
|
||||
|
||||
echo "${help_header}"
|
||||
|
@ -568,21 +568,16 @@ main() {
|
|||
#-------------------------------------------------------------------------------
|
||||
# ARGUMENT PARSING
|
||||
#-------------------------------------------------------------------------------
|
||||
OPTS=$(getopt -o hp: --long help,prefix: -n 'parse-options' -- "${@}")
|
||||
getopt_rcode="${?}"
|
||||
if [ ${getopt_rcode} != 0 ] ; then
|
||||
echo "Failed parsing options." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
eval set -- "${OPTS}"
|
||||
|
||||
while true; do
|
||||
case "${1}" in
|
||||
-p | --prefix ) PREFIX="${2}"; shift 2;;
|
||||
-h | --help ) print_help; exit 0;;
|
||||
-- ) shift; break ;;
|
||||
* ) break ;;
|
||||
OPTS="hp:"
|
||||
while getopts "${OPTS}" optchar; do
|
||||
case "${optchar}" in
|
||||
'h' ) print_help
|
||||
exit 0
|
||||
;;
|
||||
'p' ) PREFIX="${OPTARG}"
|
||||
;;
|
||||
'?' ) print_message "Unknown option ${OPTARG}" "warn"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue