Skip to content

Commit 4c00825

Browse files
committed
feat: show defaults for options/arguments
1 parent 14d5127 commit 4c00825

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/Helper/OutputHelper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,14 @@ protected function showHelp(string $for, array $items, string $header = '', stri
195195

196196
$space = 4;
197197
$group = $lastGroup = null;
198+
$withDefault = $for === 'Options' || $for === 'Arguments';
198199
foreach ($this->sortItems($items, $padLen) as $item) {
199200
$name = $this->getName($item);
200201
if ($for === 'Commands' && $lastGroup !== $group = $item->group()) {
201202
$this->writer->boldYellow($group ?: '*', true);
202203
$lastGroup = $group;
203204
}
204-
$desc = str_replace(["\r\n", "\n"], str_pad("\n", $padLen + $space + 3), $item->desc());
205+
$desc = str_replace(["\r\n", "\n"], str_pad("\n", $padLen + $space + 3), $item->desc($withDefault));
205206

206207
$this->writer->bold(' ' . str_pad($name, $padLen + $space));
207208
$this->writer->comment($desc, true);

src/Input/Parameter.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313

1414
use Ahc\Cli\Helper\InflectsString;
1515

16+
use function json_encode;
17+
use function ltrim;
1618
use function strpos;
19+
use function sprintf;
1720

1821
/**
1922
* Cli Parameter.
@@ -75,9 +78,13 @@ public function name(): string
7578
/**
7679
* Get description.
7780
*/
78-
public function desc(): string
81+
public function desc(bool $withDefault = false): string
7982
{
80-
return $this->desc;
83+
if (!$withDefault || null === $this->default || '' === $this->default) {
84+
return $this->desc;
85+
}
86+
87+
return ltrim(sprintf('%s [default: %s]', $this->desc, json_encode($this->default)));
8188
}
8289

8390
/**

0 commit comments

Comments
 (0)