From: Michael Wallner Date: Fri, 11 Sep 2015 07:16:03 +0000 (+0200) Subject: better help for positional args X-Git-Tag: v4.1.2~14 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=52a74192e5f5561f0685f644e039396525f5cec1;p=pharext%2Fpharext better help for positional args --- diff --git a/src/pharext/Cli/Args.php b/src/pharext/Cli/Args.php index c248a74..7334290 100644 --- a/src/pharext/Cli/Args.php +++ b/src/pharext/Cli/Args.php @@ -207,7 +207,7 @@ class Args implements \ArrayAccess $args = []; foreach ($this->spec as $spec) { $opt = $this->opt($spec[1]); - $args[$opt] = $this[$opt]; + $args[$opt] = is_numeric($spec[0]) ? $this[$spec[0]] : $this[$opt]; } return $args; } diff --git a/src/pharext/Cli/Args/Help.php b/src/pharext/Cli/Args/Help.php index 4284dbb..e67da9c 100644 --- a/src/pharext/Cli/Args/Help.php +++ b/src/pharext/Cli/Args/Help.php @@ -89,15 +89,34 @@ class Help function dumpPositional(array $positional) { $dump = " [--]"; + $conv = []; foreach ($positional as $pos) { - if ($pos[3] & Args::REQUIRED) { - $dump .= sprintf(" <%s>", $pos[1]); + $conv[$pos[0]][] = $pos; + } + $opts = []; + foreach ($conv as $positional) { + $args = implode("|", array_column($positional, 1)); + if ($positional[0][3] & Args::REQUIRED) { + $dump .= sprintf(" <%s>", $args); } else { - $dump .= sprintf(" [<%s>]", $pos[1]); + $dump .= sprintf(" [<%s>]", $args); + } + if ($positional[0][3] & Args::MULTI) { + $dump .= sprintf(" [<%s>]...", $args); } - if ($pos[3] & Args::MULTI) { - $dump .= sprintf(" [<%s>]...", $pos[1]); + /* + foreach ($positional as $pos) { + if ($pos[3] & Args::REQUIRED) { + $dump .= sprintf(" <%s>", $pos[1]); + } else { + $opts[] = $pos; + //$dump .= sprintf(" [<%s>]", $pos[1]); + } + if ($pos[3] & Args::MULTI) { + $dump .= sprintf(" [<%s>]...", $pos[1]); + } } + */ } return $dump; } @@ -130,8 +149,9 @@ class Help $dump .= " "; } - $dump .= str_repeat(" ", $max-strlen($spec[1])+3*!isset($spec[0])); - $dump .= $spec[2]; + $space = str_repeat(" ", $max-strlen($spec[1])+3*!isset($spec[0])); + $dump .= $space; + $dump .= str_replace("\n", "\n $space", $spec[2]); if ($spec[3] & Args::REQUIRED) { $dump .= " (REQUIRED)";