Example #1
0
 /**
  * Handles the "puli map --update" command.
  *
  * @param Args $args The console arguments.
  *
  * @return int The status code.
  */
 public function handleUpdate(Args $args)
 {
     $flags = $args->isOptionSet('force') ? RepositoryManager::OVERRIDE | RepositoryManager::IGNORE_FILE_NOT_FOUND : RepositoryManager::OVERRIDE;
     $repositoryPath = Path::makeAbsolute($args->getArgument('path'), $this->currentPath);
     $mappingToUpdate = $this->repoManager->getRootPathMapping($repositoryPath);
     $pathReferences = array_flip($mappingToUpdate->getPathReferences());
     foreach ($args->getOption('add') as $pathReference) {
         $pathReferences[$pathReference] = true;
     }
     foreach ($args->getOption('remove') as $pathReference) {
         unset($pathReferences[$pathReference]);
     }
     if (0 === count($pathReferences)) {
         $this->repoManager->removeRootPathMapping($repositoryPath);
         return 0;
     }
     $updatedMapping = new PathMapping($repositoryPath, array_keys($pathReferences));
     if ($this->mappingsEqual($mappingToUpdate, $updatedMapping)) {
         throw new RuntimeException('Nothing to update.');
     }
     $this->repoManager->addRootPathMapping($updatedMapping, $flags);
     return 0;
 }