1
0
Fork 0

Moved duplicated table render code to a new method in BaseCommand

pull/9179/head
Simon Berger 2020-09-03 15:56:04 +02:00
parent 86ff43d8b9
commit 687f886d56
4 changed files with 18 additions and 36 deletions

View File

@ -21,6 +21,7 @@ use Composer\IO\NullIO;
use Composer\Plugin\PreCommandRunEvent; use Composer\Plugin\PreCommandRunEvent;
use Composer\Package\Version\VersionParser; use Composer\Package\Version\VersionParser;
use Composer\Plugin\PluginEvents; use Composer\Plugin\PluginEvents;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
@ -202,4 +203,18 @@ abstract class BaseCommand extends Command
return $parser->parseNameVersionPairs($requirements); return $parser->parseNameVersionPairs($requirements);
} }
protected function renderTable(array $table, OutputInterface $output)
{
$renderer = new Table($output);
$renderer->setStyle('compact');
$rendererStyle = $renderer->getStyle();
if (method_exists($rendererStyle, 'setVerticalBorderChars')) {
$rendererStyle->setVerticalBorderChars('');
} else {
$rendererStyle->setVerticalBorderChar('');
}
$rendererStyle->setCellRowContentFormat('%s ');
$renderer->setRows($table)->render();
}
} }

View File

@ -24,7 +24,6 @@ use Composer\Plugin\CommandEvent;
use Composer\Plugin\PluginEvents; use Composer\Plugin\PluginEvents;
use Symfony\Component\Console\Formatter\OutputFormatterStyle; use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Composer\Package\Version\VersionParser; use Composer\Package\Version\VersionParser;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
@ -178,17 +177,7 @@ class BaseDependencyCommand extends BaseCommand
$table = array_merge($rows, $table); $table = array_merge($rows, $table);
} while (!empty($results)); } while (!empty($results));
// Render table $this->renderTable($table, $output);
$renderer = new Table($output);
$renderer->setStyle('compact');
$rendererStyle = $renderer->getStyle();
if (method_exists($rendererStyle, 'setVerticalBorderChars')) {
$rendererStyle->setVerticalBorderChars('');
} else {
$rendererStyle->setVerticalBorderChar('');
}
$rendererStyle->setCellRowContentFormat('%s ');
$renderer->setRows($table)->render();
} }
/** /**

View File

@ -15,7 +15,6 @@ namespace Composer\Command;
use Composer\Package\Link; use Composer\Package\Link;
use Composer\Package\PackageInterface; use Composer\Package\PackageInterface;
use Composer\Semver\Constraint\Constraint; use Composer\Semver\Constraint\Constraint;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
@ -169,18 +168,7 @@ EOT
$status, $status,
); );
} }
$table = array_merge($rows, $table);
// Render table $this->renderTable($rows, $output);
$renderer = new Table($output);
$renderer->setStyle('compact');
$rendererStyle = $renderer->getStyle();
if (method_exists($rendererStyle, 'setVerticalBorderChars')) {
$rendererStyle->setVerticalBorderChars('');
} else {
$rendererStyle->setVerticalBorderChar('');
}
$rendererStyle->setCellRowContentFormat('%s ');
$renderer->setRows($table)->render();
} }
} }

View File

@ -19,7 +19,6 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Helper\Table;
/** /**
* @author Fabien Potencier <fabien.potencier@gmail.com> * @author Fabien Potencier <fabien.potencier@gmail.com>
@ -130,16 +129,7 @@ EOT
$table[] = array(' '.$name, $description); $table[] = array(' '.$name, $description);
} }
$renderer = new Table($output); $this->renderTable($table, $output);
$renderer->setStyle('compact');
$rendererStyle = $renderer->getStyle();
if (method_exists($rendererStyle, 'setVerticalBorderChars')) {
$rendererStyle->setVerticalBorderChars('');
} else {
$rendererStyle->setVerticalBorderChar('');
}
$rendererStyle->setCellRowContentFormat('%s ');
$renderer->setRows($table)->render();
return 0; return 0;
} }