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_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
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue