Skip to content

Commit 62bb1f2

Browse files
committed
fix: short option check and sort options map
1 parent 190cf6f commit 62bb1f2

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

src/Contract/ParserInterface.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ public function hasShortOpts(): bool;
5656
* @param string $type The argument data type. default is: string. {@see FlagType}
5757
* @param bool $required
5858
* @param mixed|null $default
59-
* @param array $moreInfo
60-
*
61-
* @psalm-param array{alias: string, helpType: string} $moreInfo
59+
* @param array{aliases: array, helpType: string} $moreInfo
6260
*
6361
* @return self
6462
*/

src/FlagUtil.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public static function alignOptions(array $options): array
175175
}
176176

177177
// check has short option. e.g '-h, --help'
178-
$nameString = implode('|', array_keys($options));
178+
$nameString = '|' . implode('|', array_keys($options));
179179
if (preg_match('/\|-\w/', $nameString) !== 1) {
180180
return $options;
181181
}

src/Flags.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use function implode;
2424
use function is_array;
2525
use function is_string;
26+
use function ksort;
2627
use function sprintf;
2728
use function str_split;
2829
use function strlen;
@@ -746,9 +747,7 @@ protected function resetArguments(): void
746747
* @param string $type The argument data type. default is: string. {@see FlagType}
747748
* @param bool $required
748749
* @param mixed|null $default
749-
* @param array $moreInfo
750-
*
751-
* @psalm-param array{aliases: array, helpType: string} $moreInfo
750+
* @param array{aliases: array, helpType: string} $moreInfo
752751
*
753752
* @return static
754753
*/
@@ -1023,6 +1022,7 @@ public function getOptsHelpLines(): array
10231022
$helpData[$helpName] = $fmtDesc;
10241023
}
10251024

1025+
ksort($helpData);
10261026
return $helpData;
10271027
}
10281028

src/SFlags.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use function implode;
2424
use function is_callable;
2525
use function is_string;
26+
use function ksort;
2627
use function next;
2728
use function sprintf;
2829
use function str_split;
@@ -149,9 +150,7 @@ public function isNotEmpty(): bool
149150
* @param string $type The argument data type. default is: string. {@see FlagType}
150151
* @param bool $required
151152
* @param mixed|null $default
152-
* @param array $moreInfo
153-
*
154-
* @psalm-param array{alias: string, helpType: string} $moreInfo
153+
* @param array{aliases: array<string>, helpType: string} $moreInfo
155154
*
156155
* @return SFlags
157156
*/
@@ -177,6 +176,9 @@ public function addOpt(
177176
if (isset($moreInfo['helpType'])) {
178177
$define['helpType'] = $moreInfo['helpType'];
179178
}
179+
if (isset($moreInfo['aliases'])) {
180+
$define['aliases'] = $moreInfo['aliases'];
181+
}
180182

181183
$this->addOptDefine($define);
182184
return $this;
@@ -706,7 +708,7 @@ protected function addOptDefine(array $define): void
706708
$this->opts[$name] = FlagType::fmtBasicTypeValue($type, $envVal);
707709
}
708710

709-
// has shorts
711+
// has aliases
710712
if ($define['aliases']) {
711713
foreach ($define['aliases'] as $alias) {
712714
$this->setAlias($name, $alias, true);
@@ -1057,6 +1059,7 @@ public function getOptsHelpLines(): array
10571059
$helpLines[$helpName] = $fmtDesc;
10581060
}
10591061

1062+
ksort($helpLines);
10601063
return $helpLines;
10611064
}
10621065

0 commit comments

Comments
 (0)