From 92f641ac3db7aa7f46296f0b0c6b14dc21855828 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 15 Apr 2024 13:23:25 +0200 Subject: [PATCH] Fix show command output to remove v prefixes on versions, making for more uniform output, fixes #11925 --- src/Composer/Command/ShowCommand.php | 10 ++++++++-- tests/Composer/Test/Command/ShowCommandTest.php | 16 ++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/Composer/Command/ShowCommand.php b/src/Composer/Command/ShowCommand.php index 92a6e621b..a1e7eb059 100644 --- a/src/Composer/Command/ShowCommand.php +++ b/src/Composer/Command/ShowCommand.php @@ -535,10 +535,13 @@ EOT $packageViewData['homepage'] = $package instanceof CompletePackageInterface ? $package->getHomepage() : null; $packageViewData['source'] = PackageInfo::getViewSourceUrl($package); } - $nameLength = max($nameLength, strlen($package->getPrettyName())); + $nameLength = max($nameLength, strlen($packageViewData['name'])); if ($writeVersion) { $packageViewData['version'] = $package->getFullPrettyVersion(); - $versionLength = max($versionLength, strlen($package->getFullPrettyVersion())); + if ($format === 'text') { + $packageViewData['version'] = ltrim($packageViewData['version'], 'v'); + } + $versionLength = max($versionLength, strlen($packageViewData['version'])); } if ($writeReleaseDate) { if ($package->getReleaseDate() !== null) { @@ -553,6 +556,9 @@ EOT } if ($writeLatest && $latestPackage) { $packageViewData['latest'] = $latestPackage->getFullPrettyVersion(); + if ($format === 'text') { + $packageViewData['latest'] = ltrim($packageViewData['latest'], 'v'); + } $packageViewData['latest-status'] = $this->getUpdateStatus($latestPackage, $package); $latestLength = max($latestLength, strlen($packageViewData['latest'])); } elseif ($writeLatest) { diff --git a/tests/Composer/Test/Command/ShowCommandTest.php b/tests/Composer/Test/Command/ShowCommandTest.php index a8f6a2500..f807d188e 100644 --- a/tests/Composer/Test/Command/ShowCommandTest.php +++ b/tests/Composer/Test/Command/ShowCommandTest.php @@ -36,13 +36,13 @@ class ShowCommandTest extends TestCase 'packages' => [ 'type' => 'package', 'package' => [ - ['name' => 'vendor/package', 'description' => 'generic description', 'version' => '1.0.0'], + ['name' => 'vendor/package', 'description' => 'generic description', 'version' => 'v1.0.0'], - ['name' => 'outdated/major', 'description' => 'outdated/major v1.0.0 description', 'version' => '1.0.0'], - ['name' => 'outdated/major', 'description' => 'outdated/major v1.0.1 description', 'version' => '1.0.1'], - ['name' => 'outdated/major', 'description' => 'outdated/major v1.1.0 description', 'version' => '1.1.0'], - ['name' => 'outdated/major', 'description' => 'outdated/major v1.1.1 description', 'version' => '1.1.1'], - ['name' => 'outdated/major', 'description' => 'outdated/major v2.0.0 description', 'version' => '2.0.0'], + ['name' => 'outdated/major', 'description' => 'outdated/major v1.0.0 description', 'version' => 'v1.0.0'], + ['name' => 'outdated/major', 'description' => 'outdated/major v1.0.1 description', 'version' => 'v1.0.1'], + ['name' => 'outdated/major', 'description' => 'outdated/major v1.1.0 description', 'version' => 'v1.1.0'], + ['name' => 'outdated/major', 'description' => 'outdated/major v1.1.1 description', 'version' => 'v1.1.1'], + ['name' => 'outdated/major', 'description' => 'outdated/major v2.0.0 description', 'version' => 'v2.0.0'], ['name' => 'outdated/minor', 'description' => 'outdated/minor v1.0.0 description', 'version' => '1.0.0'], ['name' => 'outdated/minor', 'description' => 'outdated/minor v1.0.1 description', 'version' => '1.0.1'], @@ -57,9 +57,9 @@ class ShowCommandTest extends TestCase 'require' => $requires === [] ? new \stdClass : $requires, ]); - $pkg = self::getPackage('vendor/package', '1.0.0'); + $pkg = self::getPackage('vendor/package', 'v1.0.0'); $pkg->setDescription('description of installed package'); - $major = self::getPackage('outdated/major', '1.0.0'); + $major = self::getPackage('outdated/major', 'v1.0.0'); $major->setReleaseDate(new DateTimeImmutable()); $minor = self::getPackage('outdated/minor', '1.0.0'); $minor->setReleaseDate(new DateTimeImmutable('-2 years'));