From: Michael Wallner Date: Thu, 3 Sep 2015 11:25:10 +0000 (+0200) Subject: improve help output X-Git-Tag: v4.1.0~4 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=cd81df9ffcfe5af24c098a49b76721439bb5cf40;p=pharext%2Fpharext improve help output --- diff --git a/bin/pharext b/bin/pharext index 62ee132..85be95c 100755 Binary files a/bin/pharext and b/bin/pharext differ diff --git a/bin/pharext.update b/bin/pharext.update index f419b46..1a66284 100755 Binary files a/bin/pharext.update and b/bin/pharext.update differ diff --git a/src/pharext/Cli/Args/Help.php b/src/pharext/Cli/Args/Help.php index 50883b1..4284dbb 100644 --- a/src/pharext/Cli/Args/Help.php +++ b/src/pharext/Cli/Args/Help.php @@ -44,12 +44,10 @@ class Help foreach ($this->args->getSpec() as $spec) { if (is_numeric($spec[0])) { $positional[] = $spec; - } elseif ($spec[3] & Args::REQARG) { - if ($spec[3] & Args::REQUIRED) { - $required[] = $spec; - } else { - $optional[] = $spec; - } + } elseif ($spec[3] & Args::REQUIRED) { + $required[] = $spec; + } elseif ($spec[3] & (Args::OPTARG|Args::REQARG)) { + $optional[] = $spec; } else { $flags[] = $spec; } @@ -72,21 +70,33 @@ class Help } function dumpOptional(array $optional) { - return sprintf(" [-%s ]", implode("|-", array_column($optional, 0))); + $req = array_filter($optional, function($a) { + return $a[3] & Args::REQARG; + }); + $opt = array_filter($optional, function($a) { + return $a[3] & Args::OPTARG; + }); + + $dump = ""; + if ($req) { + $dump .= sprintf(" [-%s ]", implode("|-", array_column($req, 0))); + } + if ($opt) { + $dump .= sprintf(" [-%s []]", implode("|-", array_column($opt, 0))); + } + return $dump; } function dumpPositional(array $positional) { $dump = " [--]"; foreach ($positional as $pos) { - if ($pos[3] & Args::MULTI) { - $multi = " ..."; - } else { - $multi = ""; - } if ($pos[3] & Args::REQUIRED) { - $dump .= sprintf(" <%s%s>", $pos[1], $multi); + $dump .= sprintf(" <%s>", $pos[1]); } else { - $dump .= sprintf(" [%s%s]", $pos[1], $multi); + $dump .= sprintf(" [<%s>]", $pos[1]); + } + if ($pos[3] & Args::MULTI) { + $dump .= sprintf(" [<%s>]...", $pos[1]); } } return $dump; @@ -101,7 +111,6 @@ class Help function dumpHelp() { $max = $this->calcMaxLen(); - $parg = ""; $dump = ""; foreach ($this->args->getSpec() as $spec) { $dump .= " "; diff --git a/tests/src/pharext/CliCommandTest.php b/tests/src/pharext/CliCommandTest.php index e4f80a9..f8f4da4 100644 --- a/tests/src/pharext/CliCommandTest.php +++ b/tests/src/pharext/CliCommandTest.php @@ -42,7 +42,7 @@ class CliCommandTest extends \PHPUnit_Framework_TestCase $this->expectOutputString(<<] + $ testprog [-hvq] [-p|-n|-c ] [-s []] -h|--help Display help -v|--verbose More output