Skip to content

Commit 0e977f8

Browse files
committed
Merge branch 'fix-cli'
2 parents 8fab633 + 52e6e2c commit 0e977f8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1065
-879
lines changed

.gitattributes

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
/src/Facade/Debug.php linguist-generated
1818
/src/Facade/Err.php linguist-generated
1919
/src/Facade/Event.php linguist-generated
20-
/src/Facade/Format.php linguist-generated
2120
/src/Facade/Mapper.php linguist-generated
2221
/src/Facade/Profile.php linguist-generated
2322
/src/Facade/Sync.php linguist-generated

lk-util/Command/Generate/GenerateBuilder.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
use Lkrms\Support\PhpDoc\PhpDoc;
1111
use Lkrms\Support\PhpDoc\PhpDocTemplateTag;
1212
use Lkrms\Support\Introspector;
13-
use Lkrms\Utility\Convert;
1413
use Lkrms\Utility\Pcre;
1514
use Lkrms\Utility\Reflect;
15+
use Lkrms\Utility\Str;
1616
use Lkrms\Utility\Test;
1717
use Closure;
1818
use ReflectionMethod;
@@ -175,7 +175,7 @@ protected function run(string ...$args)
175175
$writable = $introspector->getWritableProperties();
176176
$writable = array_combine(
177177
array_map(
178-
fn(string $name) => Convert::toCamelCase($name),
178+
fn(string $name) => Str::toCamelCase($name),
179179
$writable
180180
),
181181
$writable
@@ -210,7 +210,7 @@ protected function run(string ...$args)
210210

211211
if ($_constructor = $this->InputClass->getConstructor()) {
212212
foreach ($_constructor->getParameters() as $_param) {
213-
$name = Convert::toCamelCase($_param->getName());
213+
$name = Str::toCamelCase($_param->getName());
214214
unset($writable[$name]);
215215
$_params[$name] = $_param;
216216
// Variables can't be passed to __call by reference, so this
@@ -244,7 +244,7 @@ protected function run(string ...$args)
244244
continue;
245245
}
246246
$_name = $_property->getName();
247-
$name = Convert::toCamelCase($_name);
247+
$name = Str::toCamelCase($_name);
248248
$_allProperties[$name] = $_property;
249249
if (array_key_exists($_name, $defaults)) {
250250
$_defaultProperties[$name] = $defaults[$_name];
@@ -541,8 +541,8 @@ protected function run(string ...$args)
541541
$_method->isStatic() ||
542542
strpos($name, '__') === 0 ||
543543
isset($phpDoc->TagsByName['deprecated']) ||
544-
in_array(Convert::toCamelCase($name), $names) ||
545-
in_array(Convert::toCamelCase(Pcre::replace('/^(with|get)/i', '', $name)), $names) ||
544+
in_array(Str::toCamelCase($name), $names) ||
545+
in_array(Str::toCamelCase(Pcre::replace('/^(with|get)/i', '', $name)), $names) ||
546546
in_array($name, $this->Skip) ||
547547
($this->Forward !== [] && !in_array($name, $this->Forward))) {
548548
continue;

lk-util/Command/Generate/GenerateSyncEntity.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Lkrms\Utility\Convert;
1717
use Lkrms\Utility\Inflect;
1818
use Lkrms\Utility\Pcre;
19+
use Lkrms\Utility\Str;
1920
use Closure;
2021
use DateTimeImmutable;
2122

@@ -276,7 +277,7 @@ protected function run(string ...$args)
276277
? HttpRequestMethod::POST
277278
: $this->HttpMethod;
278279
$endpoint = $endpoint === null
279-
? '/' . Convert::toKebabCase($class)
280+
? '/' . Str::toKebabCase($class)
280281
: $endpoint;
281282

282283
$curler = $provider->getCurler($endpoint);
@@ -309,7 +310,7 @@ protected static function getRemovablePrefixes(): ?array
309310
$normaliser = $entityClass::normaliser();
310311
$normaliser =
311312
fn(string $name): string =>
312-
Convert::toPascalCase($normaliser($name));
313+
Str::toPascalCase($normaliser($name));
313314

314315
$skip = [];
315316
foreach ($this->SkipProperties as $property) {

lk-util/Command/Generate/GenerateSyncProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Lkrms\Sync\Contract\ISyncProvider;
1414
use Lkrms\Sync\Support\SyncIntrospector;
1515
use Lkrms\Utility\Arr;
16-
use Lkrms\Utility\Convert;
16+
use Lkrms\Utility\Str;
1717

1818
/**
1919
* Generates provider interfaces for sync entities
@@ -148,11 +148,11 @@ protected function run(string ...$args)
148148
$this->Operations
149149
);
150150

151-
$camelClass = Convert::toCamelCase($class);
151+
$camelClass = Str::toCamelCase($class);
152152
$plural = $this->Plural === null ? $fqcn::plural() : $this->Plural;
153153

154154
if (strcasecmp($class, $plural)) {
155-
$camelPlural = Convert::toCamelCase($plural);
155+
$camelPlural = Str::toCamelCase($plural);
156156
$opMethod = [
157157
SyncOperation::CREATE => 'create' . $class,
158158
SyncOperation::READ => 'get' . $class,

lk-util/Command/Generate/GenerateTests.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
use Lkrms\Cli\CliOption;
77
use Lkrms\LkUtil\Catalog\EnvVar;
88
use Lkrms\LkUtil\Command\Generate\Concept\GenerateCommand;
9-
use Lkrms\Utility\Convert;
109
use Lkrms\Utility\Reflect;
10+
use Lkrms\Utility\Str;
1111

1212
/**
1313
* Generates PHPUnit tests
@@ -165,8 +165,8 @@ protected function run(string ...$args)
165165
continue;
166166
}
167167

168-
$testMethod = Convert::toCamelCase("test_{$method}");
169-
$providerMethod = Convert::toCamelCase("{$method}_provider");
168+
$testMethod = Str::toCamelCase("test_{$method}");
169+
$providerMethod = Str::toCamelCase("{$method}_provider");
170170

171171
$_parameters = $_method->getParameters();
172172
if ($_method->hasReturnType()) {

scripts/generate.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
use Lkrms\Utility\Arr;
3737
use Lkrms\Utility\Debugging;
3838
use Lkrms\Utility\File;
39-
use Lkrms\Utility\Formatters;
4039
use Lkrms\Utility\System;
4140

4241
$loader = require dirname(__DIR__) . '/vendor/autoload.php';
@@ -50,7 +49,6 @@
5049
Debugging::class => \Lkrms\Facade\Debug::class,
5150
ErrorHandler::class => [\Lkrms\Facade\Err::class, '--skip', 'handleShutdown,handleError,handleException'],
5251
EventDispatcher::class => \Lkrms\Facade\Event::class,
53-
Formatters::class => \Lkrms\Facade\Format::class,
5452
SyncStore::class => \Lkrms\Facade\Sync::class,
5553
Timekeeper::class => \Lkrms\Facade\Profile::class,
5654
System::class => \Lkrms\Facade\Sys::class,

src/Cli/Catalog/CliOptionValueType.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ final class CliOptionValueType extends ConvertibleEnumeration
5454
*/
5555
public const DIRECTORY = 6;
5656

57+
/**
58+
* Path to an existing file or directory, or a dash ('-') for standard input
59+
* or output
60+
*/
61+
public const PATH_OR_DASH = 7;
62+
63+
/**
64+
* Path to an existing file, or a dash ('-') for standard input or output
65+
*/
66+
public const FILE_OR_DASH = 8;
67+
5768
protected static $NameMap = [
5869
self::BOOLEAN => 'BOOLEAN',
5970
self::INTEGER => 'INTEGER',
@@ -62,6 +73,8 @@ final class CliOptionValueType extends ConvertibleEnumeration
6273
self::PATH => 'PATH',
6374
self::FILE => 'FILE',
6475
self::DIRECTORY => 'DIRECTORY',
76+
self::PATH_OR_DASH => 'PATH_OR_DASH',
77+
self::FILE_OR_DASH => 'FILE_OR_DASH',
6578
];
6679

6780
protected static $ValueMap = [
@@ -72,5 +85,7 @@ final class CliOptionValueType extends ConvertibleEnumeration
7285
'PATH' => self::PATH,
7386
'FILE' => self::FILE,
7487
'DIRECTORY' => self::DIRECTORY,
88+
'PATH_OR_DASH' => self::PATH_OR_DASH,
89+
'FILE_OR_DASH' => self::FILE_OR_DASH,
7590
];
7691
}

src/Cli/Catalog/CliOptionVisibility.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,32 @@ final class CliOptionVisibility extends Enumeration
4141
*/
4242
public const COMPLETION = 16;
4343

44+
/**
45+
* Include the option when generating a JSON Schema
46+
*/
47+
public const SCHEMA = 32;
48+
4449
/**
4550
* Hide the option's default value if not writing help to a terminal
4651
*/
47-
public const HIDE_DEFAULT = 32;
52+
public const HIDE_DEFAULT = 64;
53+
54+
/**
55+
* Show the option everywhere
56+
*/
57+
public const ALL =
58+
CliOptionVisibility::SYNOPSIS
59+
| CliOptionVisibility::HELP
60+
| CliOptionVisibility::MARKDOWN
61+
| CliOptionVisibility::MAN_PAGE
62+
| CliOptionVisibility::COMPLETION;
4863

49-
public const ALL = CliOptionVisibility::SYNOPSIS | CliOptionVisibility::HELP | CliOptionVisibility::MARKDOWN | CliOptionVisibility::MAN_PAGE | CliOptionVisibility::COMPLETION;
64+
/**
65+
* Show the option everywhere except in command synopses
66+
*/
67+
public const ALL_EXCEPT_SYNOPSIS =
68+
CliOptionVisibility::HELP
69+
| CliOptionVisibility::MARKDOWN
70+
| CliOptionVisibility::MAN_PAGE
71+
| CliOptionVisibility::COMPLETION;
5072
}

src/Cli/CliCommand.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -593,17 +593,14 @@ final public function getHelp(bool $withMarkup = true, ?int $width = 80, bool $c
593593
$synopsis = $line;
594594
}
595595

596-
if ($valueName !== null) {
597-
$valueName = $formatter->removeTags($valueName);
598-
$valueName = strtolower(Convert::splitWords($valueName, null, ' '));
599-
}
600-
601596
$lines = [];
602597
if ($option->Description !== null &&
603598
($description = trim($option->Description)) !== '') {
604599
$lines[] = $this->prepareUsage($description, $formatter, $width, $indent);
605600
}
606601

602+
$valueName = $option->getValueName();
603+
607604
if ($allowed) {
608605
foreach ($allowed as &$value) {
609606
$value = sprintf('%s- %s', $indent, $value);
@@ -660,7 +657,7 @@ final public function getHelp(bool $withMarkup = true, ?int $width = 80, bool $c
660657

661658
private function prepareUsage(?string $description, Formatter $formatter, ?int $width, ?string $indent = null): string
662659
{
663-
if (($description ?? '') === '') {
660+
if ((string) $description === '') {
664661
return '';
665662
}
666663

@@ -956,7 +953,7 @@ final protected function getOptionValues(
956953
($option->ValueOptional && $value === null))) {
957954
continue;
958955
}
959-
$name = $option->Long ?: $option->Short;
956+
$name = $option->Name;
960957
if ($nameCallback) {
961958
$name = $nameCallback($name);
962959
}
@@ -987,7 +984,7 @@ final protected function getDefaultOptionValues(?callable $nameCallback = null):
987984
$values = [];
988985
foreach ($this->Options as $option) {
989986
$value = $option->ValueOptional ? null : $option->OriginalDefaultValue;
990-
$name = $option->Long ?: $option->Short;
987+
$name = $option->Name;
991988
if ($nameCallback) {
992989
$name = $nameCallback($name);
993990
}
@@ -1155,7 +1152,7 @@ final protected function getEffectiveCommandLine(
11551152
$positional = [];
11561153
foreach ($this->Options as $option) {
11571154
$name = null;
1158-
foreach (Arr::whereNotEmpty([$option->Long, $option->Short]) as $key) {
1155+
foreach ($option->getNames() as $key) {
11591156
if (array_key_exists($key, $values)) {
11601157
$name = $key;
11611158
break;

0 commit comments

Comments
 (0)