Skip to content

Commit

Permalink
Add reference to --version (#176)
Browse files Browse the repository at this point in the history
janedbal authored Aug 8, 2024
1 parent a65295b commit bca862b
Showing 2 changed files with 19 additions and 8 deletions.
25 changes: 18 additions & 7 deletions src/Initializer.php
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
use function count;
use function get_class;
use function is_file;
use function sprintf;

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

if ($cliOptions->version !== null) {
$this->stdOutPrinter->printLine($this->deduceVersion());
$this->stdOutPrinter->printLine('Composer Dependency Analyser ' . $this->deduceVersion());
throw new AbortException();
}

@@ -270,16 +271,26 @@ public function initFormatter(CliOptions $options): ResultFormatter
private function deduceVersion(): string
{
try {
if (isset($GLOBALS['_composer_autoload_path'])) {
require $GLOBALS['_composer_autoload_path'];
}

/** @throws OutOfBoundsException */
$version = class_exists(InstalledVersions::class)
? InstalledVersions::getPrettyVersion('shipmonk/composer-dependency-analyser')
: 'unknown';
if (!class_exists(InstalledVersions::class)) {
return 'unknown';
}

$package = 'shipmonk/composer-dependency-analyser';

return sprintf(
'%s (%s)',
InstalledVersions::getPrettyVersion($package),
InstalledVersions::getReference($package)
);

} catch (OutOfBoundsException $e) {
$version = 'not found';
return 'not found';
}

return "Version: $version";
}

}
2 changes: 1 addition & 1 deletion tests/BinTest.php
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ public function test(): void
$okOutput = 'No composer issues found';
$dumpingOutput = 'Dumping sample usages of';
$helpOutput = 'Usage:';
$versionOutput = 'Version:';
$versionOutput = 'Composer Dependency Analyser';

$usingConfig = 'Using config';

0 comments on commit bca862b

Please sign in to comment.