77use Tempest \Console \Actions \ExecuteConsoleCommand ;
88use Tempest \Console \Actions \ResolveConsoleCommand ;
99use Tempest \Console \Console ;
10+ use Tempest \Console \ConsoleCommand ;
1011use Tempest \Console \ConsoleConfig ;
1112use Tempest \Console \ConsoleMiddleware ;
1213use Tempest \Console \ConsoleMiddlewareCallable ;
1314use Tempest \Console \ExitCode ;
1415use Tempest \Console \Initializers \Invocation ;
16+ use Tempest \Support \ArrayHelper ;
1517use Throwable ;
1618
1719final 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 }
0 commit comments