Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,26 @@ The API documentation is available at
Command line utility to syntax highlight SQL query:

```sh
./vendor/bin/highlight-query --query "SELECT 1"
./vendor/bin/sql-parser --highlight --query "SELECT 1"
```

Command line utility to lint SQL query:

```sh
./vendor/bin/lint-query --query "SELECT 1"
./vendor/bin/sql-parser --lint --query "SELECT 1"
```

Command line utility to tokenize SQL query:

```sh
./vendor/bin/tokenize-query --query "SELECT 1"
./vendor/bin/sql-parser --tokenize --query "SELECT 1"
```

All commands are able to parse input from stdin (standard in), such as:

```sh
echo "SELECT 1" | ./vendor/bin/highlight-query
cat example.sql | ./vendor/bin/lint-query
echo "SELECT 1" | ./vendor/bin/sql-parser --highlight
cat example.sql | ./vendor/bin/sql-parser --lint
```

### Formatting SQL query
Expand Down Expand Up @@ -116,7 +116,7 @@ The locale is automatically detected from your environment, you can also set a d
**From cli**:

```sh
LC_ALL=pl ./vendor/bin/lint-query --query "SELECT 1"
LC_ALL=pl ./vendor/bin/sql-parser --lint --query "SELECT 1"
```

**From php**:
Expand Down
30 changes: 0 additions & 30 deletions bin/highlight-query

This file was deleted.

30 changes: 0 additions & 30 deletions bin/lint-query

This file was deleted.

30 changes: 0 additions & 30 deletions bin/tokenize-query

This file was deleted.

5 changes: 1 addition & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@
"phpmyadmin/motranslator": "Translate messages to your favorite locale"
},
"bin": [
"bin/highlight-query",
"bin/lint-query",
"bin/sql-parser",
"bin/tokenize-query"
"bin/sql-parser"
],
"autoload": {
"psr-4": {
Expand Down
3 changes: 0 additions & 3 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ includes:
parameters:
level: max
paths:
- bin/highlight-query
- bin/lint-query
- bin/sql-parser
- bin/tokenize-query
- src
- tests
- tools
Expand Down
3 changes: 0 additions & 3 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
findUnusedCode="true"
>
<projectFiles>
<file name="bin/highlight-query"/>
<file name="bin/lint-query"/>
<file name="bin/sql-parser"/>
<file name="bin/tokenize-query"/>
<directory name="src"/>
<directory name="tests"/>
<directory name="tools"/>
Expand Down
42 changes: 21 additions & 21 deletions src/Utils/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ public function run(): int
$params = $this->getopt('', ['lint', 'highlight', 'tokenize']);
if ($params !== false) {
if (isset($params['lint'])) {
return $this->runLint(false);
return $this->runLint();
}

if (isset($params['highlight'])) {
return $this->runHighlight(false);
return $this->runHighlight();
}

if (isset($params['tokenize'])) {
return $this->runTokenize(false);
return $this->runTokenize();
}
}

$this->usageLint(false);
$this->usageHighlight(false);
$this->usageTokenize(false);
$this->usageLint();
$this->usageHighlight();
$this->usageTokenize();

return 1;
}
Expand All @@ -68,9 +68,9 @@ public function mergeLongOpts(array &$params, array &$longopts): void
}
}

public function usageHighlight(bool $isStandalone = true): void
public function usageHighlight(): void
{
$command = $isStandalone ? 'highlight-query' : 'sql-parser --highlight';
$command = 'sql-parser --highlight';

echo 'Usage: ' . $command . ' --query SQL [--format html|cli|text] [--ansi]' . "\n";
echo ' cat file.sql | ' . $command . "\n";
Expand Down Expand Up @@ -114,15 +114,15 @@ public function parseHighlight(): array|false
return $params;
}

public function runHighlight(bool $isStandalone = true): int
public function runHighlight(): int
{
$params = $this->parseHighlight();
if ($params === false) {
return 1;
}

if (isset($params['h'])) {
$this->usageHighlight($isStandalone);
$this->usageHighlight();

return 0;
}
Expand Down Expand Up @@ -150,14 +150,14 @@ public function runHighlight(bool $isStandalone = true): int
}

echo "ERROR: Missing parameters!\n";
$this->usageHighlight($isStandalone);
$this->usageHighlight();

return 1;
}

public function usageLint(bool $isStandalone = true): void
public function usageLint(): void
{
$command = $isStandalone ? 'lint-query' : 'sql-parser --lint';
$command = 'sql-parser --lint';

echo 'Usage: ' . $command . ' --query SQL [--ansi]' . "\n";
echo ' cat file.sql | ' . $command . "\n";
Expand All @@ -182,15 +182,15 @@ public function parseLint(): array|false
return $params;
}

public function runLint(bool $isStandalone = true): int
public function runLint(): int
{
$params = $this->parseLint();
if ($params === false) {
return 1;
}

if (isset($params['h'])) {
$this->usageLint($isStandalone);
$this->usageLint();

return 0;
}
Expand Down Expand Up @@ -227,14 +227,14 @@ public function runLint(bool $isStandalone = true): int
}

echo "ERROR: Missing parameters!\n";
$this->usageLint($isStandalone);
$this->usageLint();

return 1;
}

public function usageTokenize(bool $isStandalone = true): void
public function usageTokenize(): void
{
$command = $isStandalone ? 'tokenize-query' : 'sql-parser --tokenize';
$command = 'sql-parser --tokenize';

echo 'Usage: ' . $command . ' --query SQL [--ansi]' . "\n";
echo ' cat file.sql | ' . $command . "\n";
Expand All @@ -258,15 +258,15 @@ public function parseTokenize(): array|false
return $params;
}

public function runTokenize(bool $isStandalone = true): int
public function runTokenize(): int
{
$params = $this->parseTokenize();
if ($params === false) {
return 1;
}

if (isset($params['h'])) {
$this->usageTokenize($isStandalone);
$this->usageTokenize();

return 0;
}
Expand Down Expand Up @@ -302,7 +302,7 @@ public function runTokenize(bool $isStandalone = true): int
}

echo "ERROR: Missing parameters!\n";
$this->usageTokenize($isStandalone);
$this->usageTokenize();

return 1;
}
Expand Down
Loading