From 42eb60183eba0a2a8321ad505ee649e8410d91d1 Mon Sep 17 00:00:00 2001 From: Matthieu Moquet Date: Sat, 14 Feb 2015 17:31:33 +0100 Subject: [PATCH] Add version arg --- box.json | 1 + sqlformat.php | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/box.json b/box.json index 649b4e8..2b09be8 100644 --- a/box.json +++ b/box.json @@ -3,6 +3,7 @@ "directories": [ "vendor" ], + "git-version": "package_version", "main": "sqlformat.php", "output": "sqlformat.phar", "stub": true diff --git a/sqlformat.php b/sqlformat.php index 2719d14..c71ab36 100644 --- a/sqlformat.php +++ b/sqlformat.php @@ -3,7 +3,8 @@ require __DIR__.'/vendor/autoload.php'; -$basename = $argv[0]; +$version = "@package_version@"; +$basename = basename($argv[0]); $doc = <<] $basename [-c|--compress] [] $basename [-h | --help] + $basename [--version] Options: --no-highlight Disable highlight. @@ -18,11 +20,18 @@ --no-comment Remove comment. -c --compress Compress SQL request. -h --help Display this help. + -V --version Show the version DOC; $handler = new Docopt\Handler(); $args = $handler->handle($doc); +// Show version +if ($args['--version']) { + echo "$basename $version\n"; + return; +} + // Get SQL request for arguments or from stdin $sql = $args[''] ?: stream_get_contents(fopen("php://stdin", "r"));