Skip to content

Commit 2f7513c

Browse files
chrfrankescop
authored andcommitted
feat(_comp_compgen_help): enhance for smartctl
Allow plus sign and nested braces in short option argument.
1 parent a6c8d79 commit 2f7513c

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

bash_completion

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

test/t/unit/test_unit_parse_help.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,20 @@ 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+
"""Pattern found in the output of 'smartctl --help'."""
208+
assert_bash_exec(
209+
bash, "fn() { echo '-f A1[,A2[,A3]] --foo=A1[,A2[,A3]]'; }"
210+
)
211+
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
212+
assert output.split() == "--foo=".split()
213+
214+
def test_34(self, bash):
215+
"""Pattern found in the output of 'smartctl --help'."""
216+
assert_bash_exec(bash, "fn() { echo '-f [+]ARG --foo=[+]ARG'; }")
217+
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
218+
assert output.split() == "--foo=".split()
219+
206220
def test_custom_helpopt1(self, bash):
207221
assert_bash_exec(bash, "fn() { [[ $1 == -h ]] && echo '-option'; }")
208222
output = assert_bash_exec(bash, "_parse_help fn -h", want_output=True)

0 commit comments

Comments
 (0)