From 42c1b0289cf5ff0eec1e64cfdbcbe8d3ee0f63bb Mon Sep 17 00:00:00 2001 From: Mark Scherer Date: Fri, 21 Aug 2026 13:02:45 +0200 Subject: [PATCH] fix: report installed package version from CLI --- bin/djot | 11 +++++++++-- tests/TestCase/CliTest.php | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/bin/djot b/bin/djot index fcc272d..78edeb6 100755 --- a/bin/djot +++ b/bin/djot @@ -219,10 +219,17 @@ HELP; function showVersion(): void { - $composerJson = __DIR__ . '/../composer.json'; $version = 'unknown'; - if (file_exists($composerJson)) { + if (class_exists(Composer\InstalledVersions::class)) { + $installedVersion = Composer\InstalledVersions::getPrettyVersion('php-collective/djot'); + if (is_string($installedVersion) && $installedVersion !== '') { + $version = $installedVersion; + } + } + + $composerJson = __DIR__ . '/../composer.json'; + if ($version === 'unknown' && file_exists($composerJson)) { $data = json_decode((string)file_get_contents($composerJson), true); if (is_array($data) && isset($data['version']) && is_string($data['version'])) { $version = $data['version']; diff --git a/tests/TestCase/CliTest.php b/tests/TestCase/CliTest.php index d984851..dc79901 100644 --- a/tests/TestCase/CliTest.php +++ b/tests/TestCase/CliTest.php @@ -190,7 +190,7 @@ public function testVersionSubcommand(): void { $result = $this->runCli(['version']); $this->assertSame(0, $result['exit']); - $this->assertStringContainsString('djot-php version', $result['stdout']); + $this->assertMatchesRegularExpression('/^djot-php version (?!dev$|unknown$).+$/', trim($result['stdout'])); } public function testHelpDocumentsConvert(): void