Skip to content

Commit 074dd9f

Browse files
committed
Use git rev-parse for parsing options
1 parent 14404ad commit 074dd9f

1 file changed

Lines changed: 26 additions & 21 deletions

File tree

‎git-info‎

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,32 +37,37 @@
3737
COLOR=
3838

3939
main () {
40-
local path file first=t opt OPTIND=1 ret
41-
42-
while getopts '-:' opt; do
43-
case "$opt" in
44-
-)
45-
case "$OPTARG" in
46-
color)
47-
COLOR=always
48-
;;
49-
color\=*)
50-
COLOR="${OPTARG#color=}"
51-
;;
52-
*)
53-
die "Illegal option --$OPTARG"
54-
;;
55-
esac
40+
local opt
41+
local OPTS_SPEC="\
42+
$0 [<options>] [<path>]
43+
44+
$0 shows information about a Git repository.
45+
--
46+
h,help show the help
47+
color?when show colored output (always|never|auto)
48+
"
49+
eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt --stuck-long -- "$@" || echo exit $?)"
50+
51+
while [ $# -gt 0 ]; do
52+
opt="$1"
53+
shift
54+
55+
case "$opt" in
56+
--color)
57+
COLOR=always
5658
;;
57-
*)
58-
echo "Usage: $0 [--color[=<when>]] [path]" >&2
59-
die
59+
--color\=*)
60+
COLOR="${opt#*=}"
61+
;;
62+
--)
63+
break
64+
;;
65+
*)
66+
die "Unexpected option: $opt"
6067
;;
6168
esac
6269
done
6370

64-
shift $(($OPTIND - 1))
65-
6671
initialize_colors
6772

6873
case "$#" in

0 commit comments

Comments
 (0)