_parse_help: Pick long options also from "-f FOO, --foo=FOO".

This commit is contained in:
Ville Skyttä 2011-05-11 19:28:17 +03:00
parent f815736ffe
commit b8b46f9c27
2 changed files with 13 additions and 0 deletions

View File

@ -788,6 +788,11 @@ _parse_help()
"$cmd" ${2:---help} 2>&1 | while read -r line; do
[[ $line == *([ $'\t'])-* ]] || continue
# transform "-f FOO, --foo=FOO" to "-f , --foo=FOO" etc
while [[ $line =~ \
((^|[^-])-[A-Za-z0-9?][[:space:]]+)\[?[A-Z0-9]+\]? ]]; do
line=${line/"${BASH_REMATCH[0]}"/"${BASH_REMATCH[1]}"}
done
__parse_options "$line"
done

View File

@ -113,5 +113,13 @@ set cmd {fn() { printf '%s\n' "----\n---foo\n----- bar"; }; _parse_help fn}
assert_bash_list "" $cmd "more than two dashes"
sync_after_int
set cmd {fn() { printf '%s\n' "-f FOO, --foo=FOO"; }; _parse_help fn}
assert_bash_list "--foo=" $cmd "-f FOO, --foo=FOO"
sync_after_int
set cmd {fn() { printf '%s\n' "-f [FOO], --foo[=FOO]"; }; _parse_help fn}
assert_bash_list "--foo" $cmd "-f \[FOO\], --foo\[=FOO\]"
sync_after_int
teardown