Skip to content

Commit ef01e29

Browse files
committedAug 17, 2024
Fix bug where choice() didn't consume params on successful matching
1 parent 10220fc commit ef01e29

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed
 

‎docopt_sh/docopt.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,9 @@ choice() {
346346
: $((testdepth--))
347347
# Check if any subtree matched
348348
if [[ -n $best_match_idx ]]; then
349-
# Let the best-matching subtree set the variables
350-
[[ $testdepth -eq 0 ]] && "node_$best_match_idx"
349+
# Let the best-matching subtree consume the params
350+
# and potentially set the variables
351+
"node_$best_match_idx"
351352
return 0
352353
fi
353354
return 1

‎tests/docopt-sh-usecases.txt

+11
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,14 @@ Ending with an escaped doublequote: \"
137137
"""
138138
$ prog
139139
{}
140+
141+
#
142+
# Sequence of choices works
143+
#
144+
145+
r"""Usage:
146+
prog (a|b) (c|d)
147+
148+
"""
149+
$ prog a d
150+
{"a": true, "b": false, "c": false, "d": true}

0 commit comments

Comments
 (0)