/** * Render help text for a single command * * @param \TYPO3\FLOW3\Cli\Command $command * @return void */ protected function displayHelpForCommand(\TYPO3\FLOW3\Cli\Command $command) { $this->outputLine(); $this->outputLine('<u>' . $command->getShortDescription() . '</u>'); $this->outputLine(); $this->outputLine('<b>COMMAND:</b>'); $name = '<i>' . $command->getCommandIdentifier() . '</i>'; $this->outputLine('%-2s%s', array(' ', $name)); $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->commandManager->getShortestIdentifierForCommand($command) . ($hasOptions ? ' [<options>]' : '') . $usage; $this->outputLine(); $this->outputLine('<b>USAGE:</b>'); $this->outputLine(' %s %s', array($this->getFlow3InvocationString(), $usage)); $argumentDescriptions = array(); $optionDescriptions = array(); if ($command->hasArguments()) { foreach ($commandArgumentDefinitions as $commandArgumentDefinition) { $argumentDescription = $commandArgumentDefinition->getDescription(); $argumentDescription = wordwrap($argumentDescription, self::MAXIMUM_LINE_LENGTH - 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('<b>ARGUMENTS:</b>'); foreach ($argumentDescriptions as $argumentDescription) { $this->outputLine($argumentDescription); } } if (count($optionDescriptions) > 0) { $this->outputLine(); $this->outputLine('<b>OPTIONS:</b>'); foreach ($optionDescriptions as $optionDescription) { $this->outputLine($optionDescription); } } if ($command->getDescription() !== '') { $this->outputLine(); $this->outputLine('<b>DESCRIPTION:</b>'); $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('<b>SEE ALSO:</b>'); foreach ($relatedCommandIdentifiers as $commandIdentifier) { try { $command = $this->commandManager->getCommandByIdentifier($commandIdentifier); $this->outputLine('%-2s%s (%s)', array(' ', $commandIdentifier, $command->getShortDescription())); } catch (\TYPO3\FLOW3\Mvc\Exception\CommandException $exception) { $this->outputLine('%-2s%s (%s)', array(' ', $commandIdentifier, '<i>Command not available</i>')); } } } $this->outputLine(); }