Skip to content

Commit

Permalink
prof: display option alias on render help
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Nov 26, 2021
1 parent 679f9a0 commit ea91aa2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/Concern/HelperRenderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,6 +26,7 @@
use function strpos;
use function trim;
use function ucfirst;
use function vdump;

/**
* trait HelperRenderTrait
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/SFlags.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,12 @@ public function doParse(array $flags): bool
$isShort = true;
$option = substr($p, 1);
// long-opt: (--<opt>)
if (strpos($option, '-') === 0) {
if (str_starts_with($option, '-')) {
$isShort = false;
$option = substr($option, 1);

// long-opt: value specified inline (--<opt>=<value>)
if (strpos($option, '=') !== false) {
if (str_contains($option, '=')) {
[$option, $value] = explode('=', $option, 2);
$hasVal = $value !== '';
}
Expand Down

0 comments on commit ea91aa2

Please sign in to comment.