git.cweiske.de
/
php-sqllint.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
a3efc53
)
support reading from stdin
author
Christian Weiske
<
[email protected]
>
Tue, 15 Dec 2015 16:14:59 +0000
(17:14 +0100)
committer
Christian Weiske
<
[email protected]
>
Tue, 15 Dec 2015 16:14:59 +0000
(17:14 +0100)
src/phpsqllint/Cli.php
patch
|
blob
|
history
diff --git
a/src/phpsqllint/Cli.php
b/src/phpsqllint/Cli.php
index a417e23125ed473ef6f62623d166e0bd3013291e..5e4f6388435a2d0e3610e30441ef052c97bbd706 100644
(file)
--- a/
src/phpsqllint/Cli.php
+++ b/
src/phpsqllint/Cli.php
@@
-36,7
+36,7
@@
class Cli
public function run()
{
try {
public function run()
{
try {
- $parser = $this->load
Parameters
();
+ $parser = $this->load
OptionParser
();
$files = $this->parseParameters($parser);
$allfine = true;
$files = $this->parseParameters($parser);
$allfine = true;
@@
-66,7
+66,11
@@
class Cli
{
$this->renderer->startRendering($filename);
{
$this->renderer->startRendering($filename);
- $sql = file_get_contents($filename);
+ if ($filename == '-') {
+ $sql = file_get_contents('php://stdin');
+ } else {
+ $sql = file_get_contents($filename);
+ }
if (trim($sql) == '') {
$this->renderer->displayError('SQL file empty', '', 0, 0);
return false;
if (trim($sql) == '') {
$this->renderer->displayError('SQL file empty', '', 0, 0);
return false;
@@
-111,11
+115,12
@@
class Cli
*
* @return \Console_CommandLine CLI option parser
*/
*
* @return \Console_CommandLine CLI option parser
*/
- protected function load
Parameters
()
+ protected function load
OptionParser
()
{
$parser = new \Console_CommandLine();
$parser->description = 'php-sqllint';
$parser->version = '0.0.2';
{
$parser = new \Console_CommandLine();
$parser->description = 'php-sqllint';
$parser->version = '0.0.2';
+ $parser->avoid_reading_stdin = true;
$parser->addOption(
'renderer',
$parser->addOption(
'renderer',
@@
-136,7
+141,8
@@
class Cli
$parser->addArgument(
'sql_files',
array(
$parser->addArgument(
'sql_files',
array(
- 'multiple' => true
+ 'description' => 'SQL files, "-" for stdin',
+ 'multiple' => true
)
);
)
);
@@
-160,6
+166,9
@@
class Cli
$this->renderer = new $rendClass();
foreach ($result->args['sql_files'] as $filename) {
$this->renderer = new $rendClass();
foreach ($result->args['sql_files'] as $filename) {
+ if ($filename == '-') {
+ continue;
+ }
if (!file_exists($filename)) {
throw new \Exception('File does not exist: ' . $filename);
}
if (!file_exists($filename)) {
throw new \Exception('File does not exist: ' . $filename);
}