From fbbd6f8999ca5b5b6e5ac5dceea4021fdbb003f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Merlet?= Date: Fri, 12 Jul 2013 15:40:09 +0200 Subject: [PATCH] refactored alignment of text output --- src/Composer/Command/LicensesCommand.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Composer/Command/LicensesCommand.php b/src/Composer/Command/LicensesCommand.php index 735f24201..bd91641be 100644 --- a/src/Composer/Command/LicensesCommand.php +++ b/src/Composer/Command/LicensesCommand.php @@ -48,20 +48,22 @@ EOT $versionParser = new VersionParser; - $nameLength = strlen($root->getPrettyName()); - $versionLength = strlen($versionParser->formatVersion($root)); - foreach ($repo->getPackages() as $package) { $packages[$package->getName()] = $package; - - $nameLength = max($nameLength, strlen($package->getPrettyName())); - $versionLength = max($versionLength, strlen($versionParser->formatVersion($package))); } ksort($packages); switch ($format = $input->getOption('format')) { case 'text': + $nameLength = strlen($root->getPrettyName()); + $versionLength = strlen($versionParser->formatVersion($root)); + + foreach ($packages as $package) { + $nameLength = max($nameLength, strlen($package->getPrettyName())); + $versionLength = max($versionLength, strlen($versionParser->formatVersion($package))); + } + $formatRowCallback = function (PackageInterface $package) use ($versionParser, $nameLength, $versionLength) { return sprintf( ' %s %s %s',