cakephp / phinx

PHP Database Migrations for Everyone
https://phinx.org
MIT License
4.45k stars 895 forks source link

Argument --version does not display version #2266

Closed sljgcovas closed 2 months ago

sljgcovas commented 6 months ago

For those of us that use Phinx as standalone tool, it may be convenient that --version argument actually displays the version number and not only "hey, I'm Phinx":

$ phinx --version
Phinx by CakePHP - https://phinx.org.

The --help says: -V, --version Display this application version

Thanks :)

MasterOdin commented 2 months ago

Showing the version was removed in #1653 by @dereuromark, where I think the rationale was that updating the version field in composer.json was constantly forgotten on releases and so the info was wrong. From https://github.com/cakephp/phinx/pull/1653#issuecomment-564967668, I do think using vendor/composer/installed.php as the easiest way to re-incorporate this without having to deal with manually incrementing a version field. Just need to also validate that this file gets packed into the phar archive as well.

dereuromark commented 2 months ago

Could it read the version from the composer lock file etc?

MasterOdin commented 2 months ago

Yeah, there's three files we could use:

The first two files have the downside of that we have to load the JSON and parse it, and then do a search through an array to find robmorgan/phinx. Additionally, for development within this repo, those files will not have a reference at all for it.

The third file has the advantage where we can just require the file and then can look up the name like $installed['versions']['robmorgan/phinx']['pretty_version'] and that it'll also have an entry for within the repo (0.x-dev) which is nice.

We could also use the composer-runtime-api to further simplify things and then could do \Composer\InstalledVersions::getPrettyVersion('robmorgan/phinx'), though this does have the downside of requiring composer 2.0+ which is probably true, though not sure it's worth mandating.