Skip to content

Commit

Permalink
Fix bug where choice() didn't consume params on successful matching
Browse files Browse the repository at this point in the history
  • Loading branch information
andsens committed Aug 17, 2024
1 parent 10220fc commit ef01e29
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions docopt_sh/docopt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,9 @@ choice() {
: $((testdepth--))
# Check if any subtree matched
if [[ -n $best_match_idx ]]; then
# Let the best-matching subtree set the variables
[[ $testdepth -eq 0 ]] && "node_$best_match_idx"
# Let the best-matching subtree consume the params
# and potentially set the variables
"node_$best_match_idx"
return 0
fi
return 1
Expand Down
11 changes: 11 additions & 0 deletions tests/docopt-sh-usecases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,14 @@ Ending with an escaped doublequote: \"
"""
$ prog
{}

#
# Sequence of choices works
#

r"""Usage:
prog (a|b) (c|d)

"""
$ prog a d
{"a": true, "b": false, "c": false, "d": true}

0 comments on commit ef01e29

Please sign in to comment.