Skip to content

Commit 1ff3e42

Browse files
authored
[help] Show examples. (#157)
1 parent fce9351 commit 1ff3e42

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/Descriptor/TextDescriptor.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,41 @@ protected function describeInputDefinition(InputDefinition $definition, array $o
135135
*/
136136
protected function describeCommand(Command $command, array $options = array())
137137
{
138+
$namespace = substr(
139+
$command->getName(),
140+
0,
141+
(strpos($command->getName(), ':')?:0)
142+
);
143+
$commandData = $command->getApplication()->getData();
144+
$commands = $commandData['commands'][$namespace];
145+
$examples = [];
146+
foreach ($commands as $item) {
147+
if ($item['name'] == $command->getName()) {
148+
$examples = $item['examples'];
149+
break;
150+
}
151+
}
152+
138153
$command->getSynopsis(true);
139154
$command->getSynopsis(false);
140155
$command->mergeApplicationDefinition(false);
141156
$this->writeText($command->trans('commands.list.messages.usage'), $options);
142157
foreach (array_merge(array($command->getSynopsis(true)), $command->getAliases(), $command->getUsages()) as $usage) {
143-
$this->writeText("\n");
144158
$this->writeText(' '.$usage, $options);
159+
$this->writeText("\n");
145160
}
161+
if ($examples) {
162+
$this->writeText("\n");
163+
$this->writeText("<comment>Examples:</comment>", $options);
164+
foreach ($examples as $example) {
165+
$this->writeText("\n");
166+
$this->writeText(' '.$example['description']);
167+
$this->writeText("\n");
168+
$this->writeText(' '.$example['execution']);
169+
$this->writeText("\n");
170+
}
171+
}
172+
146173
$this->writeText("\n");
147174
$definition = $command->getNativeDefinition();
148175
if ($definition->getOptions() || $definition->getArguments()) {

0 commit comments

Comments
 (0)