diff --git a/docopt_sh/docopt.sh b/docopt_sh/docopt.sh index 3759906..fe75ed3 100644 --- a/docopt_sh/docopt.sh +++ b/docopt_sh/docopt.sh @@ -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 diff --git a/tests/docopt-sh-usecases.txt b/tests/docopt-sh-usecases.txt index b0e96f6..74d8c25 100644 --- a/tests/docopt-sh-usecases.txt +++ b/tests/docopt-sh-usecases.txt @@ -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}