Skip to content

Commit bca862b

Browse files
authored
Add reference to --version (#176)
1 parent a65295b commit bca862b

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/Initializer.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use function count;
2020
use function get_class;
2121
use function is_file;
22+
use function sprintf;
2223

2324
class Initializer
2425
{
@@ -238,7 +239,7 @@ public function initCliOptions(string $cwd, array $argv): CliOptions
238239
}
239240

240241
if ($cliOptions->version !== null) {
241-
$this->stdOutPrinter->printLine($this->deduceVersion());
242+
$this->stdOutPrinter->printLine('Composer Dependency Analyser ' . $this->deduceVersion());
242243
throw new AbortException();
243244
}
244245

@@ -270,16 +271,26 @@ public function initFormatter(CliOptions $options): ResultFormatter
270271
private function deduceVersion(): string
271272
{
272273
try {
274+
if (isset($GLOBALS['_composer_autoload_path'])) {
275+
require $GLOBALS['_composer_autoload_path'];
276+
}
277+
273278
/** @throws OutOfBoundsException */
274-
$version = class_exists(InstalledVersions::class)
275-
? InstalledVersions::getPrettyVersion('shipmonk/composer-dependency-analyser')
276-
: 'unknown';
279+
if (!class_exists(InstalledVersions::class)) {
280+
return 'unknown';
281+
}
282+
283+
$package = 'shipmonk/composer-dependency-analyser';
284+
285+
return sprintf(
286+
'%s (%s)',
287+
InstalledVersions::getPrettyVersion($package),
288+
InstalledVersions::getReference($package)
289+
);
277290

278291
} catch (OutOfBoundsException $e) {
279-
$version = 'not found';
292+
return 'not found';
280293
}
281-
282-
return "Version: $version";
283294
}
284295

285296
}

tests/BinTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function test(): void
2424
$okOutput = 'No composer issues found';
2525
$dumpingOutput = 'Dumping sample usages of';
2626
$helpOutput = 'Usage:';
27-
$versionOutput = 'Version:';
27+
$versionOutput = 'Composer Dependency Analyser';
2828

2929
$usingConfig = 'Using config';
3030

0 commit comments

Comments
 (0)