From 4472433d561c61e891dd0a437fc06a054e5d117a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sun, 22 Oct 2023 18:58:26 +0200 Subject: [PATCH] feat: Display with which version of Box the PHAR was built --- src/Console/Command/Info.php | 2 ++ src/Console/PharInfoRenderer.php | 30 ++++++++++++++++++++++++++++++ tests/Console/Command/InfoTest.php | 16 ++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/src/Console/Command/Info.php b/src/Console/Command/Info.php index 56b7641f1..69651e1a2 100644 --- a/src/Console/Command/Info.php +++ b/src/Console/Command/Info.php @@ -182,6 +182,8 @@ private static function showPharInfo( $io->newLine(); + PharInfoRenderer::renderBoxVersion($pharInfo, $io); + PharInfoRenderer::renderShortSummary( $pharInfo, $io, diff --git a/src/Console/PharInfoRenderer.php b/src/Console/PharInfoRenderer.php index 578c381ff..50096553e 100644 --- a/src/Console/PharInfoRenderer.php +++ b/src/Console/PharInfoRenderer.php @@ -38,6 +38,7 @@ use function KevinGH\Box\format_size as format_size1; use function KevinGH\Box\noop; use function key; +use function preg_match; use function round; use function Safe\filesize; use function sprintf; @@ -52,6 +53,7 @@ final class PharInfoRenderer use NotInstantiable; private const BOX_REQUIREMENTS = '.box/.requirements.php'; + private const BOX_VERSION_PATTERN = '/ \* Generated by Humbug Box (?.+)\.\s/'; private const INDENT_SIZE = 2; public static function renderShortSummary( @@ -91,6 +93,23 @@ public static function renderVersion(PharInfo $pharInfo, IO $io): void ); } + public static function renderBoxVersion(PharInfo $pharInfo, IO $io): void + { + $version = self::extractBoxVersion($pharInfo); + + if (null === $version) { + return; + } + + $io->writeln( + sprintf( + 'Built with Box: %s', + $version, + ), + ); + $io->newLine(); + } + public static function renderCompression(PharInfo $pharInfo, IO $io): void { $io->writeln( @@ -296,6 +315,17 @@ public static function renderContent( } } + private static function extractBoxVersion(PharInfo $pharInfo): ?string + { + $stub = $pharInfo->getStubContent(); + + if (null !== $stub && 1 === preg_match(self::BOX_VERSION_PATTERN, $stub, $matches)) { + return $matches['version']; + } + + return null; + } + /** * @return array{Requirement[], Requirement[]} */ diff --git a/tests/Console/Command/InfoTest.php b/tests/Console/Command/InfoTest.php index f832abda9..60d565937 100644 --- a/tests/Console/Command/InfoTest.php +++ b/tests/Console/Command/InfoTest.php @@ -313,6 +313,8 @@ public static function inputProvider(): iterable API Version: 1.1.0 + Built with Box: dev-main@b2c33cd + Archive Compression: None Files Compression: None @@ -669,6 +671,8 @@ public static function inputProvider(): iterable API Version: 1.1.0 + Built with Box: dev-main@b2c33cd + Archive Compression: None Files Compression: None @@ -698,6 +702,8 @@ public static function inputProvider(): iterable API Version: 1.1.0 + Built with Box: dev-main@b7472c2 + Archive Compression: None Files Compression: None @@ -724,6 +730,8 @@ public static function inputProvider(): iterable API Version: 1.1.0 + Built with Box: dev-main@b2c33cd + Archive Compression: None Files Compression: None @@ -752,6 +760,8 @@ public static function inputProvider(): iterable API Version: 1.1.0 + Built with Box: dev-main@b2c33cd + Archive Compression: None Files Compression: None @@ -780,6 +790,8 @@ public static function inputProvider(): iterable API Version: 1.1.0 + Built with Box: dev-main@b2c33cd + Archive Compression: None Files Compression: None @@ -808,6 +820,8 @@ public static function inputProvider(): iterable API Version: 1.1.0 + Built with Box: dev-main@b2c33cd + Archive Compression: None Files Compression: None @@ -837,6 +851,8 @@ public static function inputProvider(): iterable API Version: 1.1.0 + Built with Box: dev-main@b2c33cd + Archive Compression: None Files Compression: None