Skip to content

Commit

Permalink
feat(ScoreCommand): Read SQL from standard input if available
Browse files Browse the repository at this point in the history
- Add functionality to read SQL statements from standard input.
- Check if standard input has data before processing.
- Trim and close the standard input stream after reading.
- This change allows users to provide SQL queries directly via stdin.
  • Loading branch information
guanguans committed Oct 14, 2024
1 parent cd5ffdd commit 7ff2882
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Commands/ScoreCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public function handle(): void

$query = $soar->getQuery();

if (($fstat = fstat(STDIN)) && 0 < $fstat['size']) {
$query = trim(stream_get_contents(STDIN));
fclose(STDIN);

Check failure on line 38 in src/Commands/ScoreCommand.php

View workflow job for this annotation

GitHub Actions / psalm

InvalidPassByReference

src/Commands/ScoreCommand.php:38:20: InvalidPassByReference: Parameter 1 of fclose expects a variable (see https://psalm.dev/102)
}

for (;;) {
$query = $query ?: $this->ask('Please input the SQL statements');

Expand Down

0 comments on commit 7ff2882

Please sign in to comment.