コード例 #1
0
 /**
  * @param string $actionName
  * @throws \TYPO3\CMS\Extbase\Mvc\Exception\AmbiguousCommandIdentifierException
  * @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentTypeException
  * @throws \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException
  * @throws \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchCommandException
  * @throws \RuntimeException
  */
 protected function dispatchAction($actionName)
 {
     $this->executeSilentConfigurationUpgradesIfNeeded();
     $arguments = $this->getCommandMethodArguments($actionName . 'Command');
     $command = $this->commandManager->getCommandByIdentifier('install:' . strtolower($actionName));
     $loopCounter = 0;
     do {
         $loopCounter++;
         $this->output->outputLine();
         $this->output->outputLine(sprintf('%s:', $command->getShortDescription()));
         $actionArguments = array();
         foreach ($command->getArgumentDefinitions() as $argumentDefinition) {
             $argument = $arguments->getArgument($argumentDefinition->getName());
             if (isset($this->givenRequestArguments[$argumentDefinition->getName()])) {
                 $actionArguments[$argumentDefinition->getName()] = $this->givenRequestArguments[$argumentDefinition->getName()];
             } else {
                 if (!$this->interactiveSetup) {
                     if ($argument->isRequired()) {
                         throw new \RuntimeException(sprintf('Argument "%s" is not set, but is required and user interaction has been disabled!', $argument->getName()), 1405273316);
                     } else {
                         continue;
                     }
                 }
                 $argumentValue = NULL;
                 do {
                     $argumentValue = $this->output->ask(sprintf('<comment>%s (%s):</comment> ', $argumentDefinition->getDescription(), $argument->isRequired() ? 'required' : sprintf('default: "%s"', $argument->getDefaultValue())));
                 } while ($argumentDefinition->isRequired() && $argumentValue === NULL);
                 $actionArguments[$argumentDefinition->getName()] = $argumentValue !== NULL ? $argumentValue : $argument->getDefaultValue();
             }
         }
         do {
             $messages = @unserialize($this->dispatcher->executeCommand('install:' . strtolower($actionName), $actionArguments));
         } while ($messages === 'REDIRECT');
         $messages = $messages ?: array();
         $this->outputMessages($messages);
         if ($loopCounter > 10) {
             throw new \RuntimeException('Tried to dispatch "' . $actionName . '" ' . $loopCounter . ' times.', 1405269518);
         }
     } while (!empty($messages));
 }
コード例 #2
0
 /**
  * Render help text for a single command
  *
  * @param \TYPO3\CMS\Extbase\Mvc\Cli\Command $command
  * @return void
  */
 protected function displayHelpForCommand(\TYPO3\CMS\Extbase\Mvc\Cli\Command $command)
 {
     $this->outputLine();
     $this->outputLine($command->getShortDescription());
     $this->outputLine();
     $this->outputLine('COMMAND:');
     $this->outputLine('%-2s%s', array(' ', $command->getCommandIdentifier()));
     $commandArgumentDefinitions = $command->getArgumentDefinitions();
     $usage = '';
     $hasOptions = FALSE;
     foreach ($commandArgumentDefinitions as $commandArgumentDefinition) {
         if (!$commandArgumentDefinition->isRequired()) {
             $hasOptions = TRUE;
         } else {
             $usage .= sprintf(' <%s>', strtolower(preg_replace('/([A-Z])/', ' $1', $commandArgumentDefinition->getName())));
         }
     }
     $usage = $this->request->getCallingScript() . ' ' . $this->commandManager->getShortestIdentifierForCommand($command) . ($hasOptions ? ' [<options>]' : '') . $usage;
     $this->outputLine();
     $this->outputLine('USAGE:');
     $this->outputLine('  ' . $usage);
     $argumentDescriptions = array();
     $optionDescriptions = array();
     if ($command->hasArguments()) {
         foreach ($commandArgumentDefinitions as $commandArgumentDefinition) {
             $argumentDescription = $commandArgumentDefinition->getDescription();
             $argumentDescription = wordwrap($argumentDescription, $this->output->getMaximumLineLength() - 23, PHP_EOL . str_repeat(' ', 23), TRUE);
             if ($commandArgumentDefinition->isRequired()) {
                 $argumentDescriptions[] = vsprintf('  %-20s %s', array($commandArgumentDefinition->getDashedName(), $argumentDescription));
             } else {
                 $optionDescriptions[] = vsprintf('  %-20s %s', array($commandArgumentDefinition->getDashedName(), $argumentDescription));
             }
         }
     }
     if (count($argumentDescriptions) > 0) {
         $this->outputLine();
         $this->outputLine('ARGUMENTS:');
         foreach ($argumentDescriptions as $argumentDescription) {
             $this->outputLine($argumentDescription);
         }
     }
     if (count($optionDescriptions) > 0) {
         $this->outputLine();
         $this->outputLine('OPTIONS:');
         foreach ($optionDescriptions as $optionDescription) {
             $this->outputLine($optionDescription);
         }
     }
     if ($command->getDescription() !== '') {
         $this->outputLine();
         $this->outputLine('DESCRIPTION:');
         $descriptionLines = explode(chr(10), $command->getDescription());
         foreach ($descriptionLines as $descriptionLine) {
             $this->outputLine('%-2s%s', array(' ', $descriptionLine));
         }
     }
     $relatedCommandIdentifiers = $command->getRelatedCommandIdentifiers();
     if ($relatedCommandIdentifiers !== array()) {
         $this->outputLine();
         $this->outputLine('SEE ALSO:');
         foreach ($relatedCommandIdentifiers as $commandIdentifier) {
             $command = $this->commandManager->getCommandByIdentifier($commandIdentifier);
             $this->outputLine('%-2s%s (%s)', array(' ', $commandIdentifier, $command->getShortDescription()));
         }
     }
     $this->outputLine();
 }