Skip to content

Commit c95f110

Browse files
committed
Show version in CLI
1 parent 5830da2 commit c95f110

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

box.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"KevinGH\\Box\\Compactor\\Php"
66
],
77
"directories": ["src", "app", "data", "vendor/symfony/console/Resources"],
8+
"exclude-composer-files": false,
89
"files": [
910
"LICENSE"
1011
],
@@ -24,6 +25,6 @@
2425
"in": "vendor"
2526
}
2627
],
27-
"output": "phinx.phar",
28-
"exclude-composer-files": false
28+
"git-tag": "git_tag",
29+
"output": "phinx.phar"
2930
}

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,18 @@
3737
],
3838
"require": {
3939
"php-64bit": ">=8.1",
40+
"composer-runtime-api": "^2.0",
4041
"cakephp/database": "^5.0.2",
4142
"psr/container": "^1.1|^2.0",
42-
"symfony/console": "^6.0|^7.0",
43-
"symfony/config": "^3.4|^4.0|^5.0|^6.0|^7.0"
43+
"symfony/config": "^3.4|^4.0|^5.0|^6.0|^7.0",
44+
"symfony/console": "^6.0|^7.0"
4445
},
4546
"require-dev": {
4647
"ext-json": "*",
4748
"ext-pdo": "*",
48-
"phpunit/phpunit": "^9.5.19",
4949
"cakephp/cakephp": "^5.0.2",
5050
"cakephp/cakephp-codesniffer": "^5.0",
51+
"phpunit/phpunit": "^9.5.19",
5152
"symfony/yaml": "^3.4|^4.0|^5.0|^6.0|^7.0"
5253
},
5354
"autoload": {

src/Phinx/Console/PhinxApplication.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace Phinx\Console;
1010

11+
use Composer\InstalledVersions;
1112
use Phinx\Console\Command\Breakpoint;
1213
use Phinx\Console\Command\Create;
1314
use Phinx\Console\Command\Init;
@@ -27,12 +28,17 @@
2728
*/
2829
class PhinxApplication extends Application
2930
{
31+
/**
32+
* @var string The current application version as determined by the getVersion() function.
33+
*/
34+
private string $version;
35+
3036
/**
3137
* Initialize the Phinx console application.
3238
*/
3339
public function __construct()
3440
{
35-
parent::__construct('Phinx by CakePHP - https://phinx.org.');
41+
parent::__construct('Phinx by CakePHP - https://phinx.org.', $this->getVersion());
3642

3743
$this->addCommands([
3844
new Init(),
@@ -68,4 +74,26 @@ public function doRun(InputInterface $input, OutputInterface $output): int
6874

6975
return parent::doRun($input, $output);
7076
}
77+
78+
/**
79+
* Get the current application version.
80+
*
81+
* @return string The application version if it could be found, otherwise 'UNKNOWN'
82+
*/
83+
public function getVersion(): string
84+
{
85+
if (isset($this->version)) {
86+
return $this->version;
87+
}
88+
89+
// humbug/box will replace this with actual version when building
90+
// so use that if available
91+
$gitTag = '@git_tag@';
92+
if (!str_starts_with($gitTag, '@')) {
93+
return $this->version = $gitTag;
94+
}
95+
96+
// Otherwise fallback to the version as reported by composer
97+
return $this->version = InstalledVersions::getPrettyVersion('robmorgan/phinx') ?? 'UNKNOWN';
98+
}
7199
}

0 commit comments

Comments
 (0)