Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -1694,7 +1694,7 @@ _comp_compgen_help()
for _line in "${_lines[@]}"; do
[[ $_line == *([[:blank:]])-* ]] || continue
# transform "-f FOO, --foo=FOO" to "-f , --foo=FOO" etc
while [[ $_line =~ ((^|[^-])-[A-Za-z0-9?][[:space:]]+)\[?[A-Z0-9]+([,_-]+[A-Z0-9]+)?(\.\.+)?\]? ]]; do
while [[ $_line =~ ((^|[^-])-[A-Za-z0-9?][[:space:]]+)(\[,?)?[A-Z0-9+]+([,_-]+[A-Z0-9]+)?(\.\.+)?\]* ]]; do
_line=${_line/"${BASH_REMATCH[0]}"/"${BASH_REMATCH[1]}"}
done
_comp_compgen_help__parse "${_line// or /, }"
Expand Down
14 changes: 14 additions & 0 deletions test/t/unit/test_unit_parse_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,20 @@ def test_32(self, bash):
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
assert output.split() == "--exclude=".split()

def test_33(self, bash):
"""Pattern found in the output of 'smartctl --help'."""
assert_bash_exec(
bash, "fn() { echo '-f A1[,A2[,A3]] --foo=A1[,A2[,A3]]'; }"
)
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
assert output.split() == "--foo=".split()

def test_34(self, bash):
"""Pattern found in the output of 'smartctl --help'."""
assert_bash_exec(bash, "fn() { echo '-f [+]ARG --foo=[+]ARG'; }")
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
assert output.split() == "--foo=".split()

def test_custom_helpopt1(self, bash):
assert_bash_exec(bash, "fn() { [[ $1 == -h ]] && echo '-option'; }")
output = assert_bash_exec(bash, "_parse_help fn -h", want_output=True)
Expand Down
Loading