Skip to content

Commit

Permalink
Getopt: Don't repeat argument specification as help.
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Nov 10, 2023
1 parent 55cae3b commit f86ba55
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions lib/getopt.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,27 +237,27 @@ function help($subtype = null) {
} else {
$help = $po->help ?? "";
}
if (!isset($od[$maint])) {
if ($help !== ""
&& $help[0] === "="
&& preg_match('/\A=([A-Z]\S*)\s*/', $help, $m)) {
$argname = $m[1];
$help = substr($help, strlen($m[0]));
} else {
$argname = "ARG";
}
if ($help === "!"
|| ($subtype && !str_starts_with($help, "!{$subtype}"))
|| (!$subtype && str_starts_with($help, "!"))) {
if ($help !== ""
&& $help[0] === "="
&& preg_match('/\A=([A-Z]\S*)\s*/', $help, $m)) {
$argname = $m[1];
$help = substr($help, strlen($m[0]));
} else {
$argname = "ARG";
}
if ($help === "!"
|| ($subtype && !str_starts_with($help, "!{$subtype}"))
|| (!$subtype && str_starts_with($help, "!"))) {
continue;
}
if ($subtype) {
$help = substr($help, strlen($subtype) + 1);
if ($help !== "" && !str_starts_with($help, " ")) {
continue;
}
if ($subtype) {
$help = substr($help, strlen($subtype) + 1);
if ($help !== "" && !str_starts_with($help, " ")) {
continue;
}
$help = ltrim($help);
}
$help = ltrim($help);
}
if (!isset($od[$maint])) {
if ($po->arg === self::ARG || $po->arg === self::MARG) {
$arg = " {$argname}";
} else if ($po->arg === self::MARG2) {
Expand Down

0 comments on commit f86ba55

Please sign in to comment.