Last active
August 29, 2015 14:06
-
-
Save ambakshi/4992b41cc7d7f8048c9b to your computer and use it in GitHub Desktop.
Use git-rev-parse to do the dirty work for you
This file contains 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
#!/bin/bash | |
OPTS_SPEC="\ | |
$(basename $0 .sh) subcommand <options> | |
subcommands: | |
data - download a dataset | |
-- | |
h,help show help | |
d,debug debug output | |
v,verbose verbose output | |
f,file= input file | |
options for data | |
dataset= specify dataset to download (eg, 20140219_26816) (default: latest) | |
g,game-tag= specify game-tag (default: GAME_TAG env or hc) | |
" | |
cmd_data () { | |
echo "Hi from the data command" | |
echo "INPUT_FILE=$INPUT_FILE" | |
echo "DATASET=$DATASET" | |
echo "GAME_TAG=$GAME_TAG" | |
} | |
parse_args () { | |
if [ $# -eq 0 ]; then | |
set -- -h | |
fi | |
eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)" | |
cmd= | |
while [ $# -gt 0 ]; do | |
cmd="$1" | |
shift | |
case "$cmd" in | |
-f|--file) export INPUT_FILE="$1"; shift ;; | |
-v|--verbose) export V=1;; | |
-d|--debug) export DEBUG=1 ;; | |
--dataset) export DATASET="$1"; shift ;; | |
-g|--game-tag) export GAME_TAG="$1"; shift ;; | |
--) cmd="$1"; shift; break ;; | |
-*) echo "Unknown option $cmd" >&2; exit 1 ;; | |
esac | |
done | |
if type -t "cmd_$cmd" > /dev/null; then | |
"cmd_$cmd" | |
else | |
echo "Unknown subcommand: $cmd" >&2 | |
exit 1 | |
fi | |
} | |
main () { | |
parse_args "$@" | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment