_parse_help: Re-fix --foo[=bar] handling.

This commit is contained in:
Ville Skyttä 2011-04-27 21:44:04 +03:00
parent 3a39ac6676
commit 7b60fc6555
2 changed files with 10 additions and 2 deletions

View File

@ -754,11 +754,11 @@ _parse_help()
gsub("[,/]", " ");
x = -1;
for (i = 1; i <= NF; i++) {
if (sub("^(--.[^<[]*)", "&", $i)) { x = i ; break }
if ($i ~ /^--[^-]/) { x = i ; break }
if ($i !~ /^-/) { break }
}
if (x == -1) { x = 1 }
sub("=.*", "", $x);
sub("[=<[].*", "", $x);
print $x
}'
}

View File

@ -73,5 +73,13 @@ set cmd {fn() { printf '%s\n' "-f, -F, --foo"; }; _parse_help fn}
assert_bash_list "--foo" $cmd "short + short + long"
sync_after_int
set cmd {fn() { printf '%s\n' "--foo[=bar]"; }; _parse_help fn}
assert_bash_list "--foo" $cmd "long with value and eq sign in brackets"
sync_after_int
set cmd {fn() { printf '%s\n' "--foo=<bar>"; }; _parse_help fn}
assert_bash_list "--foo" $cmd "long with value in angle brackets"
sync_after_int
teardown