Skip to content

Commit ecdf490

Browse files
committed
feat(_comp_compgen_help): allow nested brackets behind short option
Allows `-f A1[,A2[,A3]] --foo=A1[,A2[,A3]]` as used by smartctl.
1 parent c55ee7f commit ecdf490

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

bash_completion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,7 @@ _comp_compgen_help()
16941694
for _line in "${_lines[@]}"; do
16951695
[[ $_line == *([[:blank:]])-* ]] || continue
16961696
# transform "-f FOO, --foo=FOO" to "-f , --foo=FOO" etc
1697-
while [[ $_line =~ ((^|[^-])-[A-Za-z0-9?][[:space:]]+)\[?[A-Z0-9]+([,_-]+[A-Z0-9]+)?(\.\.+)?\]? ]]; do
1697+
while [[ $_line =~ ((^|[^-])-[A-Za-z0-9?][[:space:]]+)(\[,?)?[A-Z0-9]+([,_-]+[A-Z0-9]+)?(\.\.+)?\]* ]]; do
16981698
_line=${_line/"${BASH_REMATCH[0]}"/"${BASH_REMATCH[1]}"}
16991699
done
17001700
_comp_compgen_help__parse "${_line// or /, }"

test/t/unit/test_unit_parse_help.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ def test_32(self, bash):
203203
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
204204
assert output.split() == "--exclude=".split()
205205

206+
def test_33(self, bash):
207+
assert_bash_exec(bash, "fn() { echo '-f A1[,A2[,A3]] --foo=A1[,A2[,A3]]'; }")
208+
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
209+
assert output.split() == "--foo".split()
210+
206211
def test_custom_helpopt1(self, bash):
207212
assert_bash_exec(bash, "fn() { [[ $1 == -h ]] && echo '-option'; }")
208213
output = assert_bash_exec(bash, "_parse_help fn -h", want_output=True)

0 commit comments

Comments
 (0)