Skip to content

Commit 3419131

Browse files
authored
Merge pull request #97 from adhocore/95-help-args-sort
fix(helper): arguments help output must not be sorted #95
2 parents c76e28e + 0709073 commit 3419131

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

.github/workflows/build.yml

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
- php: '8.0'
2929
- php: '8.1'
3030
- php: '8.2'
31+
- php: '8.3'
3132
fail-fast: true
3233

3334
runs-on: ubuntu-20.04

src/Helper/OutputHelper.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ protected function showHelp(string $for, array $items, string $header = '', stri
197197
$group = $lastGroup = null;
198198

199199
$withDefault = $for === 'Options' || $for === 'Arguments';
200-
foreach ($this->sortItems($items, $padLen) as $item) {
200+
foreach ($this->sortItems($items, $padLen, $for) as $item) {
201201
$name = $this->getName($item);
202202
if ($for === 'Commands' && $lastGroup !== $group = $item->group()) {
203203
$this->writer->boldYellow($group ?: '*', true);
@@ -271,13 +271,18 @@ public function showCommandNotFound(string $attempted, array $available): self
271271
*
272272
* @param Parameter[]|Command[] $items
273273
* @param int $max
274+
* @param string $for
274275
*
275276
* @return array
276277
*/
277-
protected function sortItems(array $items, &$max = 0): array
278+
protected function sortItems(array $items, &$max = 0, string $for = ''): array
278279
{
279280
$max = max(array_map(fn ($item) => strlen($this->getName($item)), $items));
280281

282+
if ($for === 'Arguments') { // Arguments are positional so must not be sorted
283+
return $items;
284+
}
285+
281286
uasort($items, static function ($a, $b) {
282287
$aName = $a instanceof Groupable ? $a->group() . $a->name() : $a->name();
283288
$bName = $b instanceof Groupable ? $b->group() . $b->name() : $b->name();

src/Output/ProgressBar.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ protected function getProgressBarStr(int $current, string $label): string
249249

250250
if ($label) {
251251
$label = $this->labelFormatted($label);
252-
// If this line doesn't have a label, but we've had one before,
253-
// then ensure the label line is cleared
252+
// If this line doesn't have a label, but we've had one before,
253+
// then ensure the label line is cleared
254254
} elseif ($this->hasLabelLine) {
255255
$label = $this->labelFormatted('');
256256
}

tests/Helper/OutputHelperTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public function test_show_arguments()
5454
'Arg Header',
5555
'',
5656
'Arguments:',
57-
' [config] [default: "defaultConfig"]',
5857
' <path> The path',
58+
' [config] [default: "defaultConfig"]',
5959
'',
6060
'Arg Footer',
6161
], $this->output());

0 commit comments

Comments
 (0)