Skip to content

Commit

Permalink
fix(helper): arguments help output must not be sorted #95
Browse files Browse the repository at this point in the history
  • Loading branch information
adhocore authored Jan 22, 2024
1 parent c76e28e commit ae8c9cd
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Helper/OutputHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ protected function showHelp(string $for, array $items, string $header = '', stri
$group = $lastGroup = null;

$withDefault = $for === 'Options' || $for === 'Arguments';
foreach ($this->sortItems($items, $padLen) as $item) {
foreach ($this->sortItems($items, $padLen, $for) as $item) {
$name = $this->getName($item);
if ($for === 'Commands' && $lastGroup !== $group = $item->group()) {
$this->writer->boldYellow($group ?: '*', true);
Expand Down Expand Up @@ -271,13 +271,18 @@ public function showCommandNotFound(string $attempted, array $available): self
*
* @param Parameter[]|Command[] $items
* @param int $max
* @param string $for
*
* @return array
*/
protected function sortItems(array $items, &$max = 0): array
protected function sortItems(array $items, &$max = 0, string $for = ''): array
{
$max = max(array_map(fn ($item) => strlen($this->getName($item)), $items));

if ($for === 'Arguments') { // Arguments are positional so must not be sorted
return $items;
}

uasort($items, static function ($a, $b) {
$aName = $a instanceof Groupable ? $a->group() . $a->name() : $a->name();
$bName = $b instanceof Groupable ? $b->group() . $b->name() : $b->name();
Expand Down

0 comments on commit ae8c9cd

Please sign in to comment.