Skip to content

Commit de6b0cb

Browse files
committed
feat(_comp_compgen_help): enhance for smartctl
Allow plus sign and nested braces in short option argument.
1 parent d6cfcf9 commit de6b0cb

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,22 @@ 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(
217+
bash, "fn() { echo '-f [+]ARG --foo=[+]ARG'; }"
218+
)
219+
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
220+
assert output.split() == "--foo=".split()
221+
206222
def test_custom_helpopt1(self, bash):
207223
assert_bash_exec(bash, "fn() { [[ $1 == -h ]] && echo '-option'; }")
208224
output = assert_bash_exec(bash, "_parse_help fn -h", want_output=True)

0 commit comments

Comments
 (0)