summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRajib Ahmed <rajib.ahmed@ztorm.com>2013-06-27 16:23:41 +0200
committerRajib Ahmed <rajib.ahmed@ztorm.com>2013-06-27 16:23:41 +0200
commit00131d65535a923d24fa32cba72df82ad9f9cfa4 (patch)
treea3e9297de59c7f56af35adb9d24128ea0a7f42d6
parent6f9501ebd4ac78eb1ff631931302891625afca32 (diff)
downloadsql-formatter-00131d65535a923d24fa32cba72df82ad9f9cfa4.zip
sql-formatter-00131d65535a923d24fa32cba72df82ad9f9cfa4.tar.gz
sql-formatter-00131d65535a923d24fa32cba72df82ad9f9cfa4.tar.bz2
Add codes to sql-script removing require_once.
-rwxr-xr-xbin/sql-formatter16
1 files changed, 15 insertions, 1 deletions
diff --git a/bin/sql-formatter b/bin/sql-formatter
index f8b7f51..4466306 100755
--- a/bin/sql-formatter
+++ b/bin/sql-formatter
@@ -1,4 +1,18 @@
#!/usr/bin/env php
<?php
+if("cli" !== php_sapi_name()) {
+ echo "<p>Run this php script from the command line to see CLI syntax highlighting and formatting. It support Unix pipes or command line argument style.</p>";
+ echo "<pre><code>php examples/cli.php \"SELECT * FROM MyTable WHERE (id>5 AND \\`name\\` LIKE \\&quot;testing\\&quot;);\"</code></pre>";
+ echo "<pre><code>echo \"SELECT * FROM MyTable WHERE (id>5 AND \\`name\\` LIKE \\&quot;testing\\&quot;);\" | php examples/cli.php</code></pre>";
+}
-require_once __DIR__.'/../examples/cli.php';
+if(isset($argv[1])) {
+ $sql = $argv[1];
+}
+else {
+ $sql = stream_get_contents(fopen("php://stdin", "r"));
+}
+
+require_once(__DIR__.'/../lib/SqlFormatter.php');
+
+echo SqlFormatter::format($sql);