コード例 #1
0
ファイル: BindCommandHandler.php プロジェクト: holloway87/cli
 /**
  * Handles the "bind --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);
     $bindingStates = $this->getBindingStates($args);
     $printBindingState = count($bindingStates) > 1;
     $printPackageName = count($packageNames) > 1;
     $printHeaders = $printBindingState || $printPackageName;
     $indentation = $printBindingState && $printPackageName ? 8 : ($printBindingState || $printPackageName ? 4 : 0);
     foreach ($bindingStates as $bindingState) {
         $bindingStatePrinted = !$printBindingState;
         foreach ($packageNames as $packageName) {
             $expr = Expr::method('getContainingPackage', Expr::method('getName', Expr::same($packageName)))->andMethod('getState', Expr::same($bindingState));
             $descriptors = $this->discoveryManager->findBindingDescriptors($expr);
             if (empty($descriptors)) {
                 continue;
             }
             if (!$bindingStatePrinted) {
                 $this->printBindingStateHeader($io, $bindingState);
                 $bindingStatePrinted = true;
             }
             if ($printPackageName) {
                 $prefix = $printBindingState ? '    ' : '';
                 $io->writeLine("{$prefix}Package: {$packageName}");
                 $io->writeLine('');
             }
             $this->printBindingTable($io, $descriptors, $indentation, BindingState::ENABLED === $bindingState);
             if ($printHeaders) {
                 $io->writeLine('');
             }
         }
     }
     return 0;
 }
コード例 #2
0
ファイル: MapCommandHandler.php プロジェクト: msojda/cli
 /**
  * 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;
 }
コード例 #3
0
 /**
  * Handles the "puli type --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->getBindingTypeStates($args);
     $printStates = count($states) > 1;
     $printPackageName = count($packageNames) > 1;
     $printHeaders = $printStates || $printPackageName;
     $printTypeAdvice = true;
     $printBindAdvice = false;
     $indentation = $printStates && $printPackageName ? 8 : ($printStates || $printPackageName ? 4 : 0);
     foreach ($states as $state) {
         $statePrinted = !$printStates;
         foreach ($packageNames as $packageName) {
             $expr = Expr::method('getContainingPackage', Expr::method('getName', Expr::same($packageName)))->andMethod('getState', Expr::same($state));
             $bindingTypes = $this->discoveryManager->findTypeDescriptors($expr);
             if (!$bindingTypes) {
                 continue;
             }
             $printTypeAdvice = false;
             if (!$statePrinted) {
                 $this->printBindingTypeState($io, $state);
                 $statePrinted = true;
                 // Only print the advice if at least one type was printed
                 $printBindAdvice = true;
             }
             if ($printPackageName) {
                 $prefix = $printStates ? '    ' : '';
                 $io->writeLine("{$prefix}Package: {$packageName}");
                 $io->writeLine('');
             }
             $styleTag = BindingTypeState::ENABLED === $state ? null : 'bad';
             $this->printTypeTable($io, $bindingTypes, $styleTag, $indentation);
             if ($printHeaders) {
                 $io->writeLine('');
             }
         }
     }
     if ($printTypeAdvice) {
         $io->writeLine('No types defined. Use "puli type --define <name>" to define a type.');
     }
     if ($printBindAdvice) {
         $io->writeLine('Use "puli bind <resource> <type>" to bind a resource to a type.');
     }
     return 0;
 }