From 29a8a8d9ccdafebaa1d56bb31ee857f85d7aba15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Goetz?= Date: Mon, 4 Jun 2018 22:52:21 +0200 Subject: [PATCH] Allow to get version with -V / --version #53 --- libs/Console/Application.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/libs/Console/Application.php b/libs/Console/Application.php index 2d292b7..a40f135 100644 --- a/libs/Console/Application.php +++ b/libs/Console/Application.php @@ -10,6 +10,26 @@ class Application extends SymfonyApplication $this->add(new Generate()); $this->add(new Serve()); + + $app_name = "daux/daux.io"; + + $up = '..' . DIRECTORY_SEPARATOR; + $composer = __DIR__ . DIRECTORY_SEPARATOR . $up . $up . $up . $up . $up . 'composer.lock'; + $version = "unknown"; + + if (file_exists($composer)) { + $app = json_decode(file_get_contents($composer)); + $packages = $app->packages; + + foreach ($packages as $package) { + if ($package->name == $app_name) { + $version = $package->version; + } + } + } + + $this->setVersion($version); + $this->setName($app_name); $this->setDefaultCommand('generate'); } }