private static function filterDuplicates(array $names, CommandCollection $commands) { $filteredNames = array(); foreach ($names as $nameToFilter) { // Check all existing names for duplicates foreach ($filteredNames as $filteredName) { // $nameToFilter is a duplicate - skip if ($commands->get($nameToFilter) === $commands->get($filteredName)) { continue 2; } } $filteredNames[] = $nameToFilter; } return $filteredNames; }
/** * @param RawArgs $args * @param CommandCollection $namedCommands * @param string[] $argumentsToTest * @param string[] $optionsToTest * * @return ResolveResult */ private function processArguments(RawArgs $args, CommandCollection $namedCommands, array $argumentsToTest, array $optionsToTest) { $currentCommand = null; // Parse the arguments for command names until we fail to find a // matching command foreach ($argumentsToTest as $name) { if (!$namedCommands->contains($name)) { break; } $nextCommand = $namedCommands->get($name); if ($nextCommand->getConfig() instanceof OptionCommandConfig) { break; } $currentCommand = $nextCommand; $namedCommands = $currentCommand->getNamedSubCommands(); } if (!$currentCommand) { return null; } return $this->processOptions($args, $currentCommand, $optionsToTest); }
/** * {@inheritdoc} */ public function getCommand($name) { return $this->commands->get($name); }
/** * @expectedException \Webmozart\Console\Api\Command\NoSuchCommandException * @expectedExceptionMessage foobar */ public function testGetFailsIfNotFound() { $this->collection->get('foobar'); }
/** * Returns the sub-command with a specific name. * * @param string $name The name of the sub-command. * * @return Command The sub-command. * * @throws NoSuchCommandException If the sub-command with the given name * does not exist. */ public function getSubCommand($name) { return $this->subCommands->get($name); }