summaryrefslogtreecommitdiffstats
path: root/examples/cli.php
diff options
context:
space:
mode:
authorJeremy Dorn <jeremy@jeremydorn.com>2013-03-15 13:25:42 -0700
committerJeremy Dorn <jeremy@jeremydorn.com>2013-03-15 13:25:42 -0700
commit46ec57eb77c2aaf6e685ecb9864ac01a5878cc77 (patch)
tree76c223470303be4cdad5aba048c182ab07532104 /examples/cli.php
parent248cceb90a7b0e6551155c28e018495052403a25 (diff)
downloadsql-formatter-46ec57eb77c2aaf6e685ecb9864ac01a5878cc77.zip
sql-formatter-46ec57eb77c2aaf6e685ecb9864ac01a5878cc77.tar.gz
sql-formatter-46ec57eb77c2aaf6e685ecb9864ac01a5878cc77.tar.bz2
Changing example cli script to work with Unix pipes and command line arguments.
Diffstat (limited to 'examples/cli.php')
-rw-r--r--examples/cli.php15
1 files changed, 14 insertions, 1 deletions
diff --git a/examples/cli.php b/examples/cli.php
index 558accf..17ee0e1 100644
--- a/examples/cli.php
+++ b/examples/cli.php
@@ -1,4 +1,17 @@
<?php
+if(php_sapi_name() !== "cli") {
+ 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>";
+}
+
+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("-- This is a cool query\nSELECT `Column1`, 'test' FROM Mytable WHERE (id >= 8); (test))(((");
+echo SqlFormatter::format($sql);