Skip to content

Commit

Permalink
Merge pull request kamranahmedse#38 from apjanke/help_option
Browse files Browse the repository at this point in the history
Add explicit -h "help" option and longer usage message
  • Loading branch information
kamranahmedse committed Apr 26, 2016
2 parents c434510 + b478362 commit ae56506
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions git-standup
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,46 @@

set -e

## Get the options and store them in variables
while getopts "d::a::w::" opt; do
declare "option_$opt=${OPTARG:-0}"
## Parse command line
function usage() {
cat <<EOS
Usage:
git standup [-a <author name>] [-w <weekstart-weekend>] [-d <days-ago>] [-h]
-a - Specify author to restrict search to
-w - Specify weekday range to limit search to
-h - Display this help screen
Examples:
git standup -a "John Doe" -w "MON-FRI"
EOS
}

while getopts "hd:a:w:" opt; do
case $opt in
h|d|a|w)
declare "option_$opt=${OPTARG:-0}"
;;
\?)
echo >&2 "Use 'git standup -h' to see usage info"
exit 1
;;
esac
done

## If some options were given but none of them were the ones that we allow
if [[ ! $option_a ]] && [[ ! $option_d ]] && [[ ! $option_w ]] && [[ $# -gt 0 ]] ; then
>&2 echo -e "Usage: $0 [-a <author name>] [-w <weekstart-weekend>] [-d <days-ago>]\nExample: $0 -a \"John Doe\" -w \"MON-FRI\""
shift $((OPTIND-1))
if [[ $# -gt 0 ]]; then
echo >&2 "Invalid arguments: $@"
echo >&2 "Use 'git standup -h' to see usage info"
exit 1
fi

# Main script

if [[ $option_h ]]; then
usage
exit 0
fi

# Use colors, but only if connected to a terminal, and that terminal
# supports them.
if [[ -t 1 ]] && [[ -n "$TERM" ]] && which tput &>/dev/null && tput colors &>/dev/null; then
Expand Down

0 comments on commit ae56506

Please sign in to comment.