/** * Handles the "puli map --list" command. * * @param Args $args The console arguments. * @param IO $io The I/O. * * @return int The status code. */ public function handleList(Args $args, IO $io) { $packageNames = ArgsUtil::getPackageNames($args, $this->packages); $states = $this->getPathMappingStates($args); $printState = count($states) > 1; $printPackageName = count($packageNames) > 1; $printHeaders = $printState || $printPackageName; $printAdvice = true; $indentation = $printState && $printPackageName ? 8 : ($printState || $printPackageName ? 4 : 0); foreach ($states as $state) { $statePrinted = !$printState; if (PathMappingState::CONFLICT === $state) { $expr = Expr::method('getContainingPackage', Expr::method('getName', Expr::in($packageNames)))->andMethod('getState', Expr::same($state)); $mappings = $this->repoManager->findPathMappings($expr); if (!$mappings) { continue; } $printAdvice = false; if ($printState) { $this->printPathMappingStateHeader($io, $state); } $this->printConflictTable($io, $mappings, $printState ? 4 : 0); if ($printHeaders) { $io->writeLine(''); } continue; } foreach ($packageNames as $packageName) { $expr = Expr::method('getContainingPackage', Expr::method('getName', Expr::same($packageName)))->andMethod('getState', Expr::same($state)); $mappings = $this->repoManager->findPathMappings($expr); if (!$mappings) { continue; } $printAdvice = false; if (!$statePrinted) { $this->printPathMappingStateHeader($io, $state); $statePrinted = true; } if ($printPackageName) { $prefix = $printState ? ' ' : ''; $io->writeLine(sprintf('%sPackage: %s', $prefix, $packageName)); $io->writeLine(''); } $this->printMappingTable($io, $mappings, $indentation, PathMappingState::ENABLED === $state); if ($printHeaders) { $io->writeLine(''); } } } if ($printAdvice) { $io->writeLine('No path mappings. Use "puli map <path> <file>" to map a Puli path to a file or directory.'); } return 0; }
public function orIn(array $values) { return $this->orX(Expr::in($values)); }
public function testRemoveConfigKeysRevertsIfSavingNotPossible() { $this->configFile->getConfig()->set(Config::PULI_DIR, 'my-puli-dir'); $this->configFileStorage->expects($this->once())->method('saveConfigFile')->willThrowException(new TestException()); try { $this->manager->removeConfigKeys(Expr::in(array(Config::PULI_DIR, Config::FACTORY_IN_FILE))); $this->fail('Expected a TestException'); } catch (TestException $e) { } $this->assertTrue($this->configFile->getConfig()->contains(Config::PULI_DIR)); $this->assertFalse($this->configFile->getConfig()->contains(Config::FACTORY_IN_FILE)); $this->assertSame('my-puli-dir', $this->configFile->getConfig()->get(Config::PULI_DIR)); }
/** * Returns the packages that should be displayed for the given console * arguments. * * @param Args $args The console arguments. * * @return PackageCollection The packages. */ private function getSelectedPackages(Args $args) { $states = $this->getSelectedStates($args); $expr = Expr::true(); $envs = array(); if ($states !== PackageState::all()) { $expr = $expr->andMethod('getState', Expr::in($states)); } if ($args->isOptionSet('installer')) { $expr = $expr->andMethod('getInstallInfo', Expr::method('getInstallerName', Expr::same($args->getOption('installer')))); } if ($args->isOptionSet('prod')) { $envs[] = Environment::PROD; } if ($args->isOptionSet('dev')) { $envs[] = Environment::DEV; } if (count($envs) > 0) { $expr = $expr->andMethod('getInstallInfo', Expr::method('getEnvironment', Expr::in($envs))); } return $this->packageManager->findPackages($expr); }
private function states(array $states) { return Expr::in($states, Package::STATE); }
public function testRemoveExtraKeysRestoresPreviousValuesIfSavingFails() { $this->rootPackageFile->setExtraKey('key1', 'previous'); $this->packageFileStorage->expects($this->once())->method('saveRootPackageFile')->with($this->rootPackageFile)->will($this->throwException(new TestException())); try { $this->manager->removeExtraKeys(Expr::in(array('key1', 'key2'))); $this->fail('Expected a TestException'); } catch (TestException $e) { } $this->assertSame('previous', $this->rootPackageFile->getExtraKey('key1')); $this->assertFalse($this->rootPackageFile->hasExtraKey('key2')); }
private function packagesAndState(array $packageNames, $state) { return Expr::in($packageNames, PathMapping::CONTAINING_PACKAGE)->andSame($state, PathMapping::STATE); }
public function andIn(array $values) { return $this->andX(Expr::in($values)); }