TYPO3 CMS  TYPO3_6-2
HelpCommandController.php
Go to the documentation of this file.
1 <?php
3 
22 
27  protected $commandManager;
28 
33 
43  public function helpStubCommand() {
44  $this->outputLine('Extbase %s', array(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getExtensionVersion('extbase')));
45  $this->outputLine('usage: ' . $this->request->getCallingScript() . ' <command identifier>');
46  $this->outputLine();
47  $this->outputLine('See \'' . $this->request->getCallingScript() . ' help\' for a list of all available commands.');
48  $this->outputLine();
49  }
50 
60  public function helpCommand($commandIdentifier = NULL) {
61  if ($commandIdentifier === NULL) {
62  $this->displayHelpIndex();
63  } else {
64  try {
65  $command = $this->commandManager->getCommandByIdentifier($commandIdentifier);
66  } catch (\TYPO3\CMS\Extbase\Mvc\Exception\CommandException $exception) {
67  $this->outputLine($exception->getMessage());
68  return;
69  }
70  $this->displayHelpForCommand($command);
71  }
72  }
73 
77  protected function displayHelpIndex() {
78  $this->buildCommandsIndex();
79  $this->outputLine('Extbase %s', array(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getExtensionVersion('extbase')));
80  $this->outputLine('usage: ' . $this->request->getCallingScript() . ' <command identifier>');
81  $this->outputLine();
82  $this->outputLine('The following commands are currently available:');
83  foreach ($this->commandsByExtensionsAndControllers as $extensionKey => $commandControllers) {
84  $this->outputLine('');
85  $this->outputLine('EXTENSION "%s":', array(strtoupper($extensionKey)));
86  $this->outputLine(str_repeat('-', self::MAXIMUM_LINE_LENGTH));
87  foreach ($commandControllers as $commands) {
88  foreach ($commands as $command) {
89  $description = wordwrap($command->getShortDescription(), self::MAXIMUM_LINE_LENGTH - 43, PHP_EOL . str_repeat(' ', 43), TRUE);
90  $shortCommandIdentifier = $this->commandManager->getShortestIdentifierForCommand($command);
91  $this->outputLine('%-2s%-40s %s', array(' ', $shortCommandIdentifier, $description));
92  }
93  $this->outputLine();
94  }
95  }
96  $this->outputLine('See \'' . $this->request->getCallingScript() . ' help <command identifier>\' for more information about a specific command.');
97  $this->outputLine();
98  }
99 
106  protected function displayHelpForCommand(\TYPO3\CMS\Extbase\Mvc\Cli\Command $command) {
107  $this->outputLine();
108  $this->outputLine($command->getShortDescription());
109  $this->outputLine();
110  $this->outputLine('COMMAND:');
111  $this->outputLine('%-2s%s', array(' ', $command->getCommandIdentifier()));
112  $commandArgumentDefinitions = $command->getArgumentDefinitions();
113  $usage = '';
114  $hasOptions = FALSE;
115  foreach ($commandArgumentDefinitions as $commandArgumentDefinition) {
116  if (!$commandArgumentDefinition->isRequired()) {
117  $hasOptions = TRUE;
118  } else {
119  $usage .= sprintf(' <%s>', strtolower(preg_replace('/([A-Z])/', ' $1', $commandArgumentDefinition->getName())));
120  }
121  }
122  $usage = $this->request->getCallingScript() . ' ' . $this->commandManager->getShortestIdentifierForCommand($command) . ($hasOptions ? ' [<options>]' : '') . $usage;
123  $this->outputLine();
124  $this->outputLine('USAGE:');
125  $this->outputLine(' ' . $usage);
126  $argumentDescriptions = array();
127  $optionDescriptions = array();
128  if ($command->hasArguments()) {
129  foreach ($commandArgumentDefinitions as $commandArgumentDefinition) {
130  $argumentDescription = $commandArgumentDefinition->getDescription();
131  $argumentDescription = wordwrap($argumentDescription, self::MAXIMUM_LINE_LENGTH - 23, PHP_EOL . str_repeat(' ', 23), TRUE);
132  if ($commandArgumentDefinition->isRequired()) {
133  $argumentDescriptions[] = vsprintf(' %-20s %s', array($commandArgumentDefinition->getDashedName(), $argumentDescription));
134  } else {
135  $optionDescriptions[] = vsprintf(' %-20s %s', array($commandArgumentDefinition->getDashedName(), $argumentDescription));
136  }
137  }
138  }
139  if (count($argumentDescriptions) > 0) {
140  $this->outputLine();
141  $this->outputLine('ARGUMENTS:');
142  foreach ($argumentDescriptions as $argumentDescription) {
143  $this->outputLine($argumentDescription);
144  }
145  }
146  if (count($optionDescriptions) > 0) {
147  $this->outputLine();
148  $this->outputLine('OPTIONS:');
149  foreach ($optionDescriptions as $optionDescription) {
150  $this->outputLine($optionDescription);
151  }
152  }
153  if ($command->getDescription() !== '') {
154  $this->outputLine();
155  $this->outputLine('DESCRIPTION:');
156  $descriptionLines = explode(chr(10), $command->getDescription());
157  foreach ($descriptionLines as $descriptionLine) {
158  $this->outputLine('%-2s%s', array(' ', $descriptionLine));
159  }
160  }
161  $relatedCommandIdentifiers = $command->getRelatedCommandIdentifiers();
162  if ($relatedCommandIdentifiers !== array()) {
163  $this->outputLine();
164  $this->outputLine('SEE ALSO:');
165  foreach ($relatedCommandIdentifiers as $commandIdentifier) {
166  $command = $this->commandManager->getCommandByIdentifier($commandIdentifier);
167  $this->outputLine('%-2s%s (%s)', array(' ', $commandIdentifier, $command->getShortDescription()));
168  }
169  }
170  $this->outputLine();
171  }
172 
180  public function errorCommand(\TYPO3\CMS\Extbase\Mvc\Exception\CommandException $exception) {
181  $this->outputLine($exception->getMessage());
182  if ($exception instanceof \TYPO3\CMS\Extbase\Mvc\Exception\AmbiguousCommandIdentifierException) {
183  $this->outputLine('Please specify the complete command identifier. Matched commands:');
184  foreach ($exception->getMatchingCommands() as $matchingCommand) {
185  $this->outputLine(' %s', array($matchingCommand->getCommandIdentifier()));
186  }
187  }
188  $this->outputLine('');
189  $this->outputLine('Enter "' . $this->request->getCallingScript() . ' help" for an overview of all available commands');
190  $this->outputLine('or "' . $this->request->getCallingScript() . ' help <command identifier>" for a detailed description of the corresponding command.');
191  }
192 
199  protected function buildCommandsIndex() {
200  $availableCommands = $this->commandManager->getAvailableCommands();
201  foreach ($availableCommands as $command) {
202  if ($command->isInternal()) {
203  continue;
204  }
205  $commandIdentifier = $command->getCommandIdentifier();
206  $extensionKey = strstr($commandIdentifier, ':', TRUE);
207  $commandControllerClassName = $command->getControllerClassName();
208  $commandName = $command->getControllerCommandName();
209  $this->commandsByExtensionsAndControllers[$extensionKey][$commandControllerClassName][$commandName] = $command;
210  }
211  }
212 }
errorCommand(\TYPO3\CMS\Extbase\Mvc\Exception\CommandException $exception)
displayHelpForCommand(\TYPO3\CMS\Extbase\Mvc\Cli\Command $command)
outputLine($text='', array $arguments=array())