Skip to content

Commit

Permalink
Add version arg
Browse files Browse the repository at this point in the history
  • Loading branch information
MattKetmo committed Feb 14, 2015
1 parent fff0ad6 commit 42eb601
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions box.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"directories": [
"vendor"
],
"git-version": "package_version",
"main": "sqlformat.php",
"output": "sqlformat.phar",
"stub": true
Expand Down
11 changes: 10 additions & 1 deletion sqlformat.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,35 @@

require __DIR__.'/vendor/autoload.php';

$basename = $argv[0];
$version = "@package_version@";
$basename = basename($argv[0]);

$doc = <<<DOC
Usage:
$basename [--no-format] [--no-highlight] [<sql>]
$basename [--no-comment] [--no-highlight] [<sql>]
$basename [-c|--compress] [<sql>]
$basename [-h | --help]
$basename [--version]
Options:
--no-highlight Disable highlight.
--no-format Disable auto formatting.
--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['<sql>'] ?: stream_get_contents(fopen("php://stdin", "r"));

Expand Down

0 comments on commit 42eb601

Please sign in to comment.