find() public static method

Searches a command collection for similar names.
public static find ( string $commandName, CommandCollection $commands ) : string[]
$commandName string The command name that was not found.
$commands Webmozart\Console\Api\Command\CommandCollection The available commands.
return string[] The names of similar commands.
 /**
  * Creates an exception for the code {@link NAME_NOT_FOUND}.
  *
  * Suggested alternatives are searched in the passed commands.
  *
  * @param string            $commandName The command name that was not found.
  * @param CommandCollection $commands    A list of available commands that
  *                                       is searched for similar names.
  * @param Exception         $cause       The exception that caused this
  *                                       exception.
  *
  * @return static The created exception.
  */
 public static function nameNotFound($commandName, CommandCollection $commands, Exception $cause = null)
 {
     $message = sprintf('The command "%s" is not defined.', $commandName);
     $suggestedNames = SimilarCommandName::find($commandName, $commands);
     if (count($suggestedNames) > 0) {
         if (1 === count($suggestedNames)) {
             $message .= "\n\nDid you mean this?\n    ";
         } else {
             $message .= "\n\nDid you mean one of these?\n    ";
         }
         $message .= implode("\n    ", $suggestedNames);
     }
     return new static($message, self::NAME_NOT_FOUND, $cause);
 }
Exemplo n.º 2
0
 /**
  * @dataProvider getInputOutput
  */
 public function testFindSimilarNames($input, array $suggestions)
 {
     $commands = new CommandCollection(array(new Command(CommandConfig::create('package')->addAlias('package-alias')), new Command(CommandConfig::create('pack')->addAlias('pack-alias')), new Command(CommandConfig::create('pack'))));
     $this->assertSame($suggestions, SimilarCommandName::find($input, $commands));
 }