|
78 | 78 | exit 1 |
79 | 79 | fi |
80 | 80 |
|
81 | | -# Parse options while taking care to leave $@ intact, so we will still |
82 | | -# have all the original command line options when executing the test |
83 | | -# script again for '--tee' and '--verbose-log' below. |
84 | 81 | store_arg_to= |
85 | | -prev_opt= |
86 | | -for opt |
87 | | -do |
88 | | - if test -n "$store_arg_to" |
| 82 | +opt_required_arg= |
| 83 | +# $1: option string |
| 84 | +# $2: name of the var where the arg will be stored |
| 85 | +mark_option_requires_arg () { |
| 86 | + if test -n "$opt_required_arg" |
89 | 87 | then |
90 | | - eval $store_arg_to=\$opt |
91 | | - store_arg_to= |
92 | | - prev_opt= |
93 | | - continue |
| 88 | + echo "error: options that require args cannot be bundled" \ |
| 89 | + "together: '$opt_required_arg' and '$1'" >&2 |
| 90 | + exit 1 |
94 | 91 | fi |
| 92 | + opt_required_arg=$1 |
| 93 | + store_arg_to=$2 |
| 94 | +} |
| 95 | + |
| 96 | +parse_option () { |
| 97 | + local opt="$1" |
95 | 98 |
|
96 | 99 | case "$opt" in |
97 | 100 | -d|--d|--de|--deb|--debu|--debug) |
|
101 | 104 | -l|--l|--lo|--lon|--long|--long-|--long-t|--long-te|--long-tes|--long-test|--long-tests) |
102 | 105 | GIT_TEST_LONG=t; export GIT_TEST_LONG ;; |
103 | 106 | -r) |
104 | | - store_arg_to=run_list |
| 107 | + mark_option_requires_arg "$opt" run_list |
105 | 108 | ;; |
106 | 109 | --run=*) |
107 | 110 | run_list=${opt#--*=} ;; |
|
185 | 188 | *) |
186 | 189 | echo "error: unknown test option '$opt'" >&2; exit 1 ;; |
187 | 190 | esac |
| 191 | +} |
| 192 | + |
| 193 | +# Parse options while taking care to leave $@ intact, so we will still |
| 194 | +# have all the original command line options when executing the test |
| 195 | +# script again for '--tee' and '--verbose-log' later. |
| 196 | +for opt |
| 197 | +do |
| 198 | + if test -n "$store_arg_to" |
| 199 | + then |
| 200 | + eval $store_arg_to=\$opt |
| 201 | + store_arg_to= |
| 202 | + opt_required_arg= |
| 203 | + continue |
| 204 | + fi |
188 | 205 |
|
189 | | - prev_opt=$opt |
| 206 | + case "$opt" in |
| 207 | + --*|-?) |
| 208 | + parse_option "$opt" ;; |
| 209 | + -?*) |
| 210 | + # bundled short options must be fed separately to parse_option |
| 211 | + opt=${opt#-} |
| 212 | + while test -n "$opt" |
| 213 | + do |
| 214 | + extra=${opt#?} |
| 215 | + this=${opt%$extra} |
| 216 | + opt=$extra |
| 217 | + parse_option "-$this" |
| 218 | + done |
| 219 | + ;; |
| 220 | + *) |
| 221 | + echo "error: unknown test option '$opt'" >&2; exit 1 ;; |
| 222 | + esac |
190 | 223 | done |
191 | 224 | if test -n "$store_arg_to" |
192 | 225 | then |
193 | | - echo "error: $prev_opt requires an argument" >&2 |
| 226 | + echo "error: $opt_required_arg requires an argument" >&2 |
194 | 227 | exit 1 |
195 | 228 | fi |
196 | 229 |
|
|
0 commit comments