/**
* {@inheritdoc}
*/
- protected function describeInputArgument(InputArgument $argument, array $options = array())
+ protected function describeInputArgument(InputArgument $argument, array $options = [])
{
if (null !== $argument->getDefault() && (!is_array($argument->getDefault()) || count($argument->getDefault()))) {
$default = sprintf('<comment> [default: %s]</comment>', $this->formatDefaultValue($argument->getDefault()));
/**
* {@inheritdoc}
*/
- protected function describeInputOption(InputOption $option, array $options = array())
+ protected function describeInputOption(InputOption $option, array $options = [])
{
if ($option->acceptValue() && null !== $option->getDefault() && (!is_array($option->getDefault()) || count($option->getDefault()))) {
$default = sprintf('<comment> [default: %s]</comment>', $this->formatDefaultValue($option->getDefault()));
$value = '['.$value.']';
}
}
- $totalWidth = isset($options['total_width']) ? $options['total_width'] : $this->calculateTotalWidthForOptions(array($option));
+ $totalWidth = isset($options['total_width']) ? $options['total_width'] : $this->calculateTotalWidthForOptions([$option]);
$synopsis = sprintf(
'%s%s',
$option->getShortcut() ? sprintf('-%s, ', $option->getShortcut()) : ' ',
/**
* {@inheritdoc}
*/
- protected function describeInputDefinition(InputDefinition $definition, array $options = array())
+ protected function describeInputDefinition(InputDefinition $definition, array $options = [])
{
$totalWidth = $this->calculateTotalWidthForOptions($definition->getOptions());
foreach ($definition->getArguments() as $argument) {
$this->writeText($options['translator']->trans('commands.list.messages.arguments'), $options);
$this->writeText("\n");
foreach ($definition->getArguments() as $argument) {
- $this->describeInputArgument($argument, array_merge($options, array('total_width' => $totalWidth)));
+ $this->describeInputArgument($argument, array_merge($options, ['total_width' => $totalWidth]));
$this->writeText("\n");
}
}
$this->writeText("\n");
}
if ($definition->getOptions()) {
- $laterOptions = array();
+ $laterOptions = [];
$this->writeText($options['translator']->trans('commands.list.messages.options'), $options);
foreach ($definition->getOptions() as $option) {
if (strlen($option->getShortcut()) > 1) {
continue;
}
$this->writeText("\n");
- $this->describeInputOption($option, array_merge($options, array('total_width' => $totalWidth)));
+ $this->describeInputOption($option, array_merge($options, ['total_width' => $totalWidth]));
}
foreach ($laterOptions as $option) {
$this->writeText("\n");
- $this->describeInputOption($option, array_merge($options, array('total_width' => $totalWidth)));
+ $this->describeInputOption($option, array_merge($options, ['total_width' => $totalWidth]));
}
}
}
/**
* {@inheritdoc}
*/
- protected function describeCommand(Command $command, array $options = array())
+ protected function describeCommand(Command $command, array $options = [])
{
+ $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");
+ foreach (array_merge([$command->getSynopsis(true)], $command->getAliases(), $command->getUsages()) as $usage) {
$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()) {
/**
* {@inheritdoc}
*/
- protected function describeApplication(Application $application, array $options = array())
+ protected function describeApplication(Application $application, array $options = [])
{
$describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
$description = new ApplicationDescription($application, $describedNamespace);
$width = $this->getColumnWidth($description->getCommands()) + 4;
if ($describedNamespace) {
$this->writeText(sprintf($application->trans('commands.list.messages.comment'), $describedNamespace), $options);
- }
- else {
+ } else {
$this->writeText($application->trans('commands.list.messages.available-commands'), $options);
}
$this->writeText(' <comment>'.$namespace['id'].'</comment>', $options);
}
foreach ($namespace['commands'] as $name) {
-
- if (ApplicationDescription::GLOBAL_NAMESPACE == $namespace['id']){
+ if (ApplicationDescription::GLOBAL_NAMESPACE == $namespace['id']) {
if (!in_array($name, $singleCommands)) {
continue;
}
$this->writeText("\n");
$alias = '';
- if ($description->getCommand($name)->getAliases()){
+ if ($description->getCommand($name)->getAliases()) {
$alias = sprintf(
'(%s)',
implode(',', $description->getCommand($name)->getAliases())
}
$spacingWidth = $width - strlen($name.$alias);
$this->writeText(
- sprintf(' <info>%s</info> <comment>%s</comment> %s%s',
+ sprintf(
+ ' <info>%s</info> <comment>%s</comment> %s%s',
$name,
$alias,
str_repeat(' ', $spacingWidth),
/**
* {@inheritdoc}
*/
- private function writeText($content, array $options = array())
+ private function writeText($content, array $options = [])
{
$this->write(
isset($options['raw_text']) && $options['raw_text'] ? strip_tags($content) : $content,