Skip to content

Commit 107f8b8

Browse files
authored
feat(console): provide command suggestions when using : shorthands (#814)
1 parent 88bd85d commit 107f8b8

File tree

11 files changed

+28
-26
lines changed

11 files changed

+28
-26
lines changed

src/Tempest/Cache/src/CacheClearCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function __construct(
1818
) {
1919
}
2020

21-
#[ConsoleCommand(name: 'cache:clear', description: 'Clears all or specified caches', aliases: ['cc'])]
21+
#[ConsoleCommand(name: 'cache:clear', description: 'Clears all or specified caches')]
2222
public function __invoke(bool $all = false): void
2323
{
2424
$caches = $this->cacheConfig->caches;

src/Tempest/Cache/src/CacheStatusCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function __construct(
2020
) {
2121
}
2222

23-
#[ConsoleCommand(name: 'cache:status', description: 'Shows which caches are enabled', aliases: ['cs'])]
23+
#[ConsoleCommand(name: 'cache:status', description: 'Shows which caches are enabled')]
2424
public function __invoke(): void
2525
{
2626
$caches = $this->cacheConfig->caches;

src/Tempest/Console/src/Commands/TailDebugLogCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function __construct(
2222
) {
2323
}
2424

25-
#[ConsoleCommand('tail:debug', description: 'Tails the debug log', aliases: ['td'])]
25+
#[ConsoleCommand('tail:debug', description: 'Tails the debug log')]
2626
public function __invoke(): void
2727
{
2828
$debugLogPath = $this->logConfig->debugLogPath;

src/Tempest/Console/src/Commands/TailProjectLogCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function __construct(
2323
) {
2424
}
2525

26-
#[ConsoleCommand('tail:project', description: 'Tails the project log', aliases: ['tp'])]
26+
#[ConsoleCommand('tail:project', description: 'Tails the project log')]
2727
public function __invoke(): void
2828
{
2929
$appendLogChannel = null;

src/Tempest/Console/src/Commands/TailServerLogCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function __construct(
2222
) {
2323
}
2424

25-
#[ConsoleCommand('tail:server', description: 'Tails the server log', aliases: ['ts'])]
25+
#[ConsoleCommand('tail:server', description: 'Tails the server log')]
2626
public function __invoke(): void
2727
{
2828
$serverLogPath = $this->logConfig->serverLogPath;

src/Tempest/Console/src/Middleware/ResolveOrRescueMiddleware.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
use Tempest\Console\Actions\ExecuteConsoleCommand;
88
use Tempest\Console\Actions\ResolveConsoleCommand;
99
use Tempest\Console\Console;
10+
use Tempest\Console\ConsoleCommand;
1011
use Tempest\Console\ConsoleConfig;
1112
use Tempest\Console\ConsoleMiddleware;
1213
use Tempest\Console\ConsoleMiddlewareCallable;
1314
use Tempest\Console\ExitCode;
1415
use Tempest\Console\Initializers\Invocation;
16+
use Tempest\Support\ArrayHelper;
1517
use Throwable;
1618

1719
final readonly class ResolveOrRescueMiddleware implements ConsoleMiddleware
@@ -70,11 +72,23 @@ private function getSimilarCommands(string $name): array
7072
{
7173
$similarCommands = [];
7274

75+
/** @var ConsoleCommand $consoleCommand */
7376
foreach ($this->consoleConfig->commands as $consoleCommand) {
7477
if (in_array($consoleCommand->getName(), $similarCommands, strict: true)) {
7578
continue;
7679
}
7780

81+
if (str_contains($name, ':')) {
82+
$wantedParts = ArrayHelper::explode($name, separator: ':');
83+
$currentParts = ArrayHelper::explode($consoleCommand->getName(), separator: ':');
84+
85+
if ($wantedParts->count() === $currentParts->count() && $wantedParts->every(fn (string $part, int $index) => str_starts_with($currentParts[$index], $part))) {
86+
$similarCommands[] = $consoleCommand->getName();
87+
88+
continue;
89+
}
90+
}
91+
7892
if (str_starts_with($consoleCommand->getName(), $name)) {
7993
$similarCommands[] = $consoleCommand->getName();
8094

@@ -83,7 +97,7 @@ private function getSimilarCommands(string $name): array
8397

8498
$levenshtein = levenshtein($name, $consoleCommand->getName());
8599

86-
if ($levenshtein <= 3) {
100+
if ($levenshtein <= 2) {
87101
$similarCommands[] = $consoleCommand->getName();
88102
}
89103
}

src/Tempest/Core/src/Commands/DiscoveryClearCommand.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ public function __construct(
1616
) {
1717
}
1818

19-
#[ConsoleCommand(
20-
name: 'discovery:clear',
21-
description: 'Clears all cached discovery files',
22-
aliases: ['dc'],
23-
)]
19+
#[ConsoleCommand(name: 'discovery:clear', description: 'Clears all cached discovery files')]
2420
public function __invoke(): void
2521
{
2622
$this->discoveryCache->clear();

src/Tempest/Core/src/Commands/DiscoveryGenerateCommand.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ public function __construct(
2424
) {
2525
}
2626

27-
#[ConsoleCommand(
28-
name: 'discovery:generate',
29-
description: 'Compile and cache all discovery according to the configured discovery caching strategy',
30-
aliases: ['dg'],
31-
)]
27+
#[ConsoleCommand(name: 'discovery:generate', description: 'Compile and cache all discovery according to the configured discovery caching strategy')]
3228
public function __invoke(): void
3329
{
3430
$strategy = $this->resolveDiscoveryCacheStrategy();

src/Tempest/Core/src/Commands/DiscoveryStatusCommand.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ public function __construct(
1818
) {
1919
}
2020

21-
#[ConsoleCommand(
22-
name: 'discovery:status',
23-
description: 'Lists all discovery locations and discovery classes',
24-
aliases: ['ds'],
25-
)]
21+
#[ConsoleCommand(name: 'discovery:status', description: 'Lists all discovery locations and discovery classes')]
2622
public function __invoke(): void
2723
{
2824
$this->console->writeln('<h2>Registered discovery classes</h2>');

src/Tempest/Framework/Commands/ConfigShowCommand.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ public function __construct(
3131
) {
3232
}
3333

34-
#[ConsoleCommand(
35-
name: 'config:show',
36-
description: 'Show resolved configuration',
37-
aliases: ['config'],
38-
)]
34+
#[ConsoleCommand(name: 'config:show', description: 'Show resolved configuration', aliases: ['config'])]
3935
public function __invoke(
4036
ConfigShowFormat $format = ConfigShowFormat::PRETTY,
4137
?bool $search = false,

0 commit comments

Comments
 (0)