1
0
Fork 0

Do case-insensitive searches, avoid printing multiple results if multiple tokens match, highlight matched area

pull/149/head
Jordi Boggiano 2011-12-06 23:07:47 +01:00
parent c7deaa8a1f
commit 283745d76d
1 changed files with 8 additions and 3 deletions

View File

@ -46,16 +46,21 @@ EOT
// create local repo, this contains all packages that are installed in the local project // create local repo, this contains all packages that are installed in the local project
$localRepo = $composer->getRepositoryManager()->getLocalRepository(); $localRepo = $composer->getRepositoryManager()->getLocalRepository();
$tokens = array_map('strtolower', $input->getArgument('tokens'));
foreach ($composer->getRepositoryManager()->getRepositories() as $repository) { foreach ($composer->getRepositoryManager()->getRepositories() as $repository) {
foreach ($repository->getPackages() as $package) { foreach ($repository->getPackages() as $package) {
foreach ((array) $input->getArgument('tokens') as $token) { foreach ($tokens as $token) {
if (false === strpos($package->getName(), $token)) { if (false === ($pos = strpos($package->getName(), $token))) {
continue; continue;
} }
$state = $localRepo->hasPackage($package) ? '<info>installed</info>' : $state = '<comment>available</comment>'; $state = $localRepo->hasPackage($package) ? '<info>installed</info>' : $state = '<comment>available</comment>';
$output->writeln($state . ': ' . $package->getPrettyName() . ' <comment>' . $package->getPrettyVersion() . '</comment>'); $name = substr($package->getPrettyName(), 0, $pos)
. '<highlight>' . substr($package->getPrettyName(), $pos, strlen($token)) . '</highlight>'
. substr($package->getPrettyName(), $pos + strlen($token));
$output->writeln($state . ': ' . $name . ' <comment>' . $package->getPrettyVersion() . '</comment>');
continue 2;
} }
} }
} }