From ea91aa262bb12e96d07ccdfd93e6b5f0f2da0f35 Mon Sep 17 00:00:00 2001 From: Inhere Date: Fri, 26 Nov 2021 13:16:05 +0800 Subject: [PATCH] prof: display option alias on render help --- src/Concern/HelperRenderTrait.php | 10 ++++++++-- src/SFlags.php | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Concern/HelperRenderTrait.php b/src/Concern/HelperRenderTrait.php index fc1b04f..c93b049 100644 --- a/src/Concern/HelperRenderTrait.php +++ b/src/Concern/HelperRenderTrait.php @@ -11,6 +11,7 @@ use Toolkit\Stdlib\Helper\DataHelper; use Toolkit\Stdlib\Helper\IntHelper; use Toolkit\Stdlib\Str; +use function array_merge; use function array_push; use function array_shift; use function count; @@ -25,6 +26,7 @@ use function strpos; use function trim; use function ucfirst; +use function vdump; /** * trait HelperRenderTrait @@ -346,9 +348,13 @@ protected function buildOptsForHelp(array $optDefines, bool $hasShortOpt): array */ protected function buildOptHelpLine(string $name, array $opt): array { - $names = $opt['shorts']; - $names[] = $name; + $names = $opt['shorts']; + // has aliases + if ($opt['aliases']) { + $names = array_merge($names, $opt['aliases']); + } + $names[] = $name; $helpName = FlagUtil::buildOptHelpName($names); // show type name. diff --git a/src/SFlags.php b/src/SFlags.php index 3714636..f0bf0e9 100644 --- a/src/SFlags.php +++ b/src/SFlags.php @@ -375,12 +375,12 @@ public function doParse(array $flags): bool $isShort = true; $option = substr($p, 1); // long-opt: (--) - if (strpos($option, '-') === 0) { + if (str_starts_with($option, '-')) { $isShort = false; $option = substr($option, 1); // long-opt: value specified inline (--=) - if (strpos($option, '=') !== false) { + if (str_contains($option, '=')) { [$option, $value] = explode('=', $option, 2); $hasVal = $value !== ''; }