public function find(string $possibleName): string
    {
        $allCommands = $this->getNames();
        $expr = preg_replace_callback('{([^:]+|)}', function ($matches) {
            return preg_quote($matches[1], '/') . '[^:]*';
        }, $possibleName);
        $commands = preg_grep('{^' . $expr . '}', $allCommands);

        if (empty($commands)) {
            $commands = preg_grep('{^' . $expr . '}i', $allCommands);
        }

        // filter out aliases for commands which are already on the list
        if (count($commands) > 1) {
            $commandList = $this->commands;
            $commands = array_unique(array_filter($commands, function ($nameOrAlias) use ($commandList, $commands) {
                $commandName = $commandList[$nameOrAlias]['name'];

                return $commandName === $nameOrAlias || !in_array($commandName, $commands, true);
            }));
        }

        return !empty($commands) && count($commands) === 1 ? $this->commands[reset($commands)]['name'] : $possibleName;
    }
public function find(string $possibleName): string
    {
        $allCommands = $this->getNames();
        $expr = preg_replace_callback('{([^:]+|)}', function ($matches) {
            return preg_quote($matches[1], '/') . '[^:]*';
        }, $possibleName);
        $commands = preg_grep('{^' . $expr . '}', $allCommands);

        if (empty($commands)) {
            $commands = preg_grep('{^' . $expr . '}i', $allCommands);
        }

        // filter out aliases for commands which are already on the list
        if (count($commands) > 1) {
            $commandList = $this->commands;
            $commands = array_unique(array_filter($commands, function ($nameOrAlias) use ($commandList, $commands) {
                $commandName = $commandList[$nameOrAlias]['name'];

                return $commandName === $nameOrAlias || !in_array($commandName, $commands, true);
            }));
        }

        return !empty($commands) && count($commands) === 1 ? $this->commands[reset($commands)]['name'] : $possibleName;
    }
public function find ( string $ possibleName ) : string { $ allCommands = $ this -> getNames ( ) ; $ expr = preg_replace_callback ( '{([^:]+|)}' , function ( $ matches ) { return preg_quote ( $ matches [ 1 ] , '/' ) . '[^:]*' ; } , $ possibleName ) ; $ commands = preg_grep ( '{^' . $ expr . '}' , $ allCommands ) ; if ( empty ( $ commands ) ) { $ commands = preg_grep ( '{^' . $ expr . '}i' , $ allCommands ) ; } // filter out aliases for commands which are already on the list if ( count ( $ commands ) > 1 ) { $ commandList = $ this -> commands ; $ commands = array_unique ( array_filter ( $ commands , function ( $ nameOrAlias ) use ( $ commandList , $ commands ) { $ commandName = $ commandList [ $ nameOrAlias ] [ 'name' ] ; return $ commandName === $ nameOrAlias || ! in_array ( $ commandName , $ commands , true ) ; } ) ) ; } return ! empty ( $ commands ) && count ( $ commands ) === 1 ? $ this -> commands [ reset ( $ commands ) ] [ 'name' ] : $ possibleName ; }
Try resolving short command names and aliases
If that fails, we return the command name as is and let the application throw an exception.

Inspired by \Symfony\Component\Console\Application::find()

@param string $possibleName
@return string
Try resolving short command names and aliases If that fails we return the command name as is and let the application throw an exception .