Skip to content

Commit

Permalink
Show version in CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterOdin committed Jun 10, 2024
1 parent 5830da2 commit 958e13c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,18 @@
],
"require": {
"php-64bit": ">=8.1",
"composer-runtime-api": "*",
"cakephp/database": "^5.0.2",
"psr/container": "^1.1|^2.0",
"symfony/console": "^6.0|^7.0",
"symfony/config": "^3.4|^4.0|^5.0|^6.0|^7.0"
"symfony/config": "^3.4|^4.0|^5.0|^6.0|^7.0",
"symfony/console": "^6.0|^7.0"
},
"require-dev": {
"ext-json": "*",
"ext-pdo": "*",
"phpunit/phpunit": "^9.5.19",
"cakephp/cakephp": "^5.0.2",
"cakephp/cakephp-codesniffer": "^5.0",
"phpunit/phpunit": "^9.5.19",
"symfony/yaml": "^3.4|^4.0|^5.0|^6.0|^7.0"
},
"autoload": {
Expand Down
22 changes: 21 additions & 1 deletion src/Phinx/Console/PhinxApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Phinx\Console;

use Composer\InstalledVersions;
use Phinx\Console\Command\Breakpoint;
use Phinx\Console\Command\Create;
use Phinx\Console\Command\Init;
Expand All @@ -27,12 +28,17 @@
*/
class PhinxApplication extends Application
{
/**
* @var string The current application version as determined by the getVersion() function.
*/
private string $version;

/**
* Initialize the Phinx console application.
*/
public function __construct()
{
parent::__construct('Phinx by CakePHP - https://phinx.org.');
parent::__construct('Phinx by CakePHP - https://phinx.org.', $this->getVersion());

$this->addCommands([
new Init(),
Expand Down Expand Up @@ -68,4 +74,18 @@ public function doRun(InputInterface $input, OutputInterface $output): int

return parent::doRun($input, $output);
}

/**
* Get the current application version.
*
* @return string The application version if it could be found, otherwise 'UNKNOWN'
*/
public function getVersion(): string
{
if (isset($this->version)) {
return $this->version;
}

return $this->version = InstalledVersions::getPrettyVersion('robmorgan/phinx') ?? 'UNKNOWN';
}
}

0 comments on commit 958e13c

Please sign in to comment.