Skip to content

Commit ae56506

Browse files
committed
Merge pull request #38 from apjanke/help_option
Add explicit -h "help" option and longer usage message
2 parents c434510 + b478362 commit ae56506

1 file changed

Lines changed: 36 additions & 7 deletions

File tree

git-standup

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,46 @@
22

33
set -e
44

5-
## Get the options and store them in variables
6-
while getopts "d::a::w::" opt; do
7-
declare "option_$opt=${OPTARG:-0}"
5+
## Parse command line
6+
function usage() {
7+
cat <<EOS
8+
Usage:
9+
git standup [-a <author name>] [-w <weekstart-weekend>] [-d <days-ago>] [-h]
10+
11+
-a - Specify author to restrict search to
12+
-w - Specify weekday range to limit search to
13+
-h - Display this help screen
14+
15+
Examples:
16+
git standup -a "John Doe" -w "MON-FRI"
17+
EOS
18+
}
19+
20+
while getopts "hd:a:w:" opt; do
21+
case $opt in
22+
h|d|a|w)
23+
declare "option_$opt=${OPTARG:-0}"
24+
;;
25+
\?)
26+
echo >&2 "Use 'git standup -h' to see usage info"
27+
exit 1
28+
;;
29+
esac
830
done
9-
10-
## If some options were given but none of them were the ones that we allow
11-
if [[ ! $option_a ]] && [[ ! $option_d ]] && [[ ! $option_w ]] && [[ $# -gt 0 ]] ; then
12-
>&2 echo -e "Usage: $0 [-a <author name>] [-w <weekstart-weekend>] [-d <days-ago>]\nExample: $0 -a \"John Doe\" -w \"MON-FRI\""
31+
shift $((OPTIND-1))
32+
if [[ $# -gt 0 ]]; then
33+
echo >&2 "Invalid arguments: $@"
34+
echo >&2 "Use 'git standup -h' to see usage info"
1335
exit 1
1436
fi
1537

38+
# Main script
39+
40+
if [[ $option_h ]]; then
41+
usage
42+
exit 0
43+
fi
44+
1645
# Use colors, but only if connected to a terminal, and that terminal
1746
# supports them.
1847
if [[ -t 1 ]] && [[ -n "$TERM" ]] && which tput &>/dev/null && tput colors &>/dev/null; then

0 commit comments

Comments
 (0)