Skip to content

Commit

Permalink
[help] Show examples. (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmolivas committed May 6, 2017
1 parent fce9351 commit 1ff3e42
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/Descriptor/TextDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,41 @@ protected function describeInputDefinition(InputDefinition $definition, array $o
*/
protected function describeCommand(Command $command, array $options = array())
{
$namespace = substr(
$command->getName(),
0,
(strpos($command->getName(), ':')?:0)
);
$commandData = $command->getApplication()->getData();
$commands = $commandData['commands'][$namespace];
$examples = [];
foreach ($commands as $item) {
if ($item['name'] == $command->getName()) {
$examples = $item['examples'];
break;
}
}

$command->getSynopsis(true);
$command->getSynopsis(false);
$command->mergeApplicationDefinition(false);
$this->writeText($command->trans('commands.list.messages.usage'), $options);
foreach (array_merge(array($command->getSynopsis(true)), $command->getAliases(), $command->getUsages()) as $usage) {
$this->writeText("\n");
$this->writeText(' '.$usage, $options);
$this->writeText("\n");
}
if ($examples) {
$this->writeText("\n");
$this->writeText("<comment>Examples:</comment>", $options);
foreach ($examples as $example) {
$this->writeText("\n");
$this->writeText(' '.$example['description']);
$this->writeText("\n");
$this->writeText(' '.$example['execution']);
$this->writeText("\n");
}
}

$this->writeText("\n");
$definition = $command->getNativeDefinition();
if ($definition->getOptions() || $definition->getArguments()) {
Expand Down

0 comments on commit 1ff3e42

Please sign in to comment.