Last active
November 7, 2016 09:25
-
-
Save maximkott/136410a724c03428cea5d73a29174fd3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
source "helpers" | |
SCRIPT_PATH=${0%/*} | |
SCRIPT_NAME=${0##*/} | |
# @help Parse given arguments and match them | |
# to local variables. | |
# @usage parse <args...> | |
parse() { | |
# iterate over all arguments | |
while [[ "$#" > 0 ]]; do | |
# assume that the first argument | |
# is a flag and the second the flag value | |
flag="$1" | |
val="$2" | |
# value must not be a flag | |
if [[ ! "$val" || "$val" == -* ]]; then | |
val= | |
fi | |
case "$flag" in | |
# display usage | |
-h|--help) usage;; | |
# enable interactive mode | |
-*) error "Invalid option $flag";; | |
esac; | |
done | |
} | |
# @help Write usage information about this script and exit. | |
# @usage help | |
usage() { | |
echo " | |
Usage: | |
$SCRIPT_NAME | |
Options: | |
-h --help Show help | |
" | |
exit 1; | |
} | |
main() { | |
parse "$@" | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment