Update git-sh-setup(1) to allow transparent use of git-rev-parse --parseopt
If you set OPTIONS_SPEC, git-sh-setups uses git-rev-parse --parseopt automatically. It also diverts usage to re-exec $0 with the -h option as parse-options.c will catch that. If you need git-rev-parse --parseopt to keep the `--` the user may have passed to your command, set OPTIONS_KEEPDASHDASH to a non empty value in your script. Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Pierre Habouzit committed
Nov 4, 2007 at 11:30 UTC
bac199b7b17cd12286a7d5393f4789574c2e1dc4
1 file changed
+30
-18
git-sh-setup.sh
+30
-18
@@ -16,9 +16,36 @@ die() {
16
exit 1
17
}
18
19
-usage() {
20
- die "Usage: $0 $USAGE"
21
-}
19
+if test -n "$OPTIONS_SPEC"; then
20
+ usage() {
21
+ exec "$0" -h
22
+ }
23
+
24
+ parseopt_extra=
25
+ [ -n "$OPTIONS_KEEPDASHDASH" ] &&
26
+ parseopt_extra="$parseopt_extra --keep-dashdash"
27
+
28
+ eval `echo "$OPTIONS_SPEC" | git rev-parse --parseopt $parseopt_extra -- "$@" || echo exit $?`
29
+else
30
+ usage() {
31
+ die "Usage: $0 $USAGE"
32
+ }
33
+
34
+ if [ -z "$LONG_USAGE" ]
35
+ then
36
+ LONG_USAGE="Usage: $0 $USAGE"
37
+ else
38
+ LONG_USAGE="Usage: $0 $USAGE
39
+
40
+$LONG_USAGE"
41
+ fi
42
+
43
+ case "$1" in
44
+ -h|--h|--he|--hel|--help)
45
+ echo "$LONG_USAGE"
46
+ exit
47
+ esac
48
+fi
49
50
set_reflog_action() {
51
if [ -z "${GIT_REFLOG_ACTION:+set}" ]
@@ -91,21 +118,6 @@ get_author_ident_from_commit () {
118
LANG=C LC_ALL=C sed -ne "$pick_author_script"
119
}
120
94
-if [ -z "$LONG_USAGE" ]
95
-then
96
- LONG_USAGE="Usage: $0 $USAGE"
97
-else
98
- LONG_USAGE="Usage: $0 $USAGE
99
-
100
-$LONG_USAGE"
101
-fi
102
-
103
-case "$1" in
104
- -h|--h|--he|--hel|--help)
105
- echo "$LONG_USAGE"
106
- exit
107
-esac
108
-
121
# Make sure we are in a valid repository of a vintage we understand.
122
if [ -z "$SUBDIRECTORY_OK" ]
123
then