|
18 | 18 | use Lkrms\Contract\IReadable; |
19 | 19 | use Lkrms\Facade\Assert; |
20 | 20 | use Lkrms\Facade\Console; |
| 21 | +use Lkrms\Support\Catalog\CharacterSequence as Char; |
21 | 22 | use Lkrms\Utility\Convert; |
22 | 23 | use Lkrms\Utility\Env; |
23 | 24 | use Lkrms\Utility\Test; |
@@ -327,7 +328,7 @@ public function __construct( |
327 | 328 | $this->Short = $this->IsPositional ? null : ($short ?: null); |
328 | 329 | $this->Key = $this->IsPositional ? $long : ($short . '|' . $long); |
329 | 330 | $this->ValueName = $this->IsFlag ? null : ($valueName ?: ($this->IsPositional ? Convert::toSnakeCase($long, '=') : null) ?: 'value'); |
330 | | - $this->DisplayName = $this->IsPositional ? $this->getFriendlyValueName() : ($long ? '--' . $long : '-' . $short); |
| 331 | + $this->DisplayName = $this->IsPositional ? $this->getFriendlyValueName(false) : ($long ? '--' . $long : '-' . $short); |
331 | 332 | $this->ValueType = $this->IsFlag ? ($multipleAllowed ? CliOptionValueType::INTEGER : CliOptionValueType::BOOLEAN) : $valueType; |
332 | 333 | $this->Delimiter = $multipleAllowed && !$this->IsFlag ? $delimiter : null; |
333 | 334 | $this->Description = $description; |
@@ -411,16 +412,28 @@ public function getNames(): array |
411 | 412 | /** |
412 | 413 | * Format the option's value name |
413 | 414 | * |
| 415 | + * If {@see CliOption::$ValueName} contains angle brackets (`<`, `>`), it is |
| 416 | + * returned as-is, otherwise: |
| 417 | + * |
| 418 | + * - if it contains uppercase characters and no lowercase characters, it is |
| 419 | + * converted to kebab-case and capitalised |
| 420 | + * - if not, it is converted to kebab-case and enclosed between angle |
| 421 | + * brackets |
| 422 | + * |
| 423 | + * In conversions to kebab-case, `=` is preserved. |
414 | 424 | */ |
415 | | - public function getFriendlyValueName(): ?string |
| 425 | + public function getFriendlyValueName(bool $withMarkup = true): ?string |
416 | 426 | { |
417 | | - $name = $this->ValueName; |
418 | | - $upper = $name === strtoupper($name); |
419 | | - $name = Convert::toKebabCase($name, '='); |
420 | | - if ($upper) { |
421 | | - return '<' . strtoupper($name) . '>'; |
| 427 | + if ($this->ValueName === null || strpbrk($this->ValueName, '<>') !== false) { |
| 428 | + return $this->ValueName; |
| 429 | + } |
| 430 | + |
| 431 | + if (strpbrk($this->ValueName, Char::ALPHABETIC_UPPER) !== false && |
| 432 | + strpbrk($this->ValueName, Char::ALPHABETIC_LOWER) === false) { |
| 433 | + [$before, $after] = $withMarkup ? ['<', '>'] : ['', '']; |
| 434 | + return $before . strtoupper(Convert::toKebabCase($this->ValueName, '=')) . $after; |
422 | 435 | } |
423 | | - return "<$name>"; |
| 436 | + return '<' . Convert::toKebabCase($this->ValueName, '=') . '>'; |
424 | 437 | } |
425 | 438 |
|
426 | 439 | /** |
|
0 commit comments