From 1a6e3ee8c75579d179dd440b1a61d3c900372457 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 16 Jan 2018 09:19:44 +0100 Subject: [PATCH] Show script description for custom commands in run-script --list, fixes #7009 --- src/Composer/Command/RunScriptCommand.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Composer/Command/RunScriptCommand.php b/src/Composer/Command/RunScriptCommand.php index 929056946..d78662e23 100644 --- a/src/Composer/Command/RunScriptCommand.php +++ b/src/Composer/Command/RunScriptCommand.php @@ -19,6 +19,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Helper\Table; /** * @author Fabien Potencier @@ -68,7 +69,7 @@ EOT protected function execute(InputInterface $input, OutputInterface $output) { if ($input->getOption('list')) { - return $this->listScripts(); + return $this->listScripts($output); } elseif (!$input->getArgument('script')) { throw new \RuntimeException('Missing required argument "script"'); } @@ -101,7 +102,7 @@ EOT return $composer->getEventDispatcher()->dispatchScript($script, $devMode, $args); } - protected function listScripts() + protected function listScripts(OutputInterface $output) { $scripts = $this->getComposer()->getPackage()->getScripts(); @@ -111,10 +112,22 @@ EOT $io = $this->getIO(); $io->writeError('scripts:'); + $table = array(); foreach ($scripts as $name => $script) { - $io->write(' ' . $name); + $cmd = $this->getApplication()->find($name); + $description = ''; + if ($cmd instanceof ScriptAliasCommand) { + $description = $cmd->getDescription(); + } + $table[] = array(' '.$name, $description); } + $renderer = new Table($output); + $renderer->setStyle('compact'); + $renderer->getStyle()->setVerticalBorderChar(''); + $renderer->getStyle()->setCellRowContentFormat('%s '); + $renderer->setRows($table)->render(); + return 0; } }