From c236c90bea0cf57a5c5fa8893bc52ea46728aa1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Fri, 25 Oct 2024 19:54:57 -0300 Subject: [PATCH] Remove alternative executable files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- README.md | 12 ++++----- bin/highlight-query | 30 --------------------- bin/lint-query | 30 --------------------- bin/tokenize-query | 30 --------------------- composer.json | 5 +--- phpstan.neon.dist | 3 --- psalm.xml | 3 --- src/Utils/CLI.php | 42 ++++++++++++++--------------- tests/Utils/CLITest.php | 60 ++++++++++++++++++++--------------------- 9 files changed, 58 insertions(+), 157 deletions(-) delete mode 100755 bin/highlight-query delete mode 100755 bin/lint-query delete mode 100755 bin/tokenize-query diff --git a/README.md b/README.md index af54459ab..b0f31ecce 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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**: diff --git a/bin/highlight-query b/bin/highlight-query deleted file mode 100755 index 53d380f2b..000000000 --- a/bin/highlight-query +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env php -runHighlight()); diff --git a/bin/lint-query b/bin/lint-query deleted file mode 100755 index 1fe12f2fb..000000000 --- a/bin/lint-query +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env php -runLint()); diff --git a/bin/tokenize-query b/bin/tokenize-query deleted file mode 100755 index e1a55f6b0..000000000 --- a/bin/tokenize-query +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env php -runTokenize()); diff --git a/composer.json b/composer.json index 1658be383..2156af8e2 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 1150357e1..017678af6 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -3,10 +3,7 @@ includes: parameters: level: max paths: - - bin/highlight-query - - bin/lint-query - bin/sql-parser - - bin/tokenize-query - src - tests - tools diff --git a/psalm.xml b/psalm.xml index 98035037f..8c2d8cde7 100644 --- a/psalm.xml +++ b/psalm.xml @@ -10,10 +10,7 @@ findUnusedCode="true" > - - - diff --git a/src/Utils/CLI.php b/src/Utils/CLI.php index 2da78aaef..f0bf2c27a 100644 --- a/src/Utils/CLI.php +++ b/src/Utils/CLI.php @@ -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; } @@ -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"; @@ -114,7 +114,7 @@ public function parseHighlight(): array|false return $params; } - public function runHighlight(bool $isStandalone = true): int + public function runHighlight(): int { $params = $this->parseHighlight(); if ($params === false) { @@ -122,7 +122,7 @@ public function runHighlight(bool $isStandalone = true): int } if (isset($params['h'])) { - $this->usageHighlight($isStandalone); + $this->usageHighlight(); return 0; } @@ -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"; @@ -182,7 +182,7 @@ public function parseLint(): array|false return $params; } - public function runLint(bool $isStandalone = true): int + public function runLint(): int { $params = $this->parseLint(); if ($params === false) { @@ -190,7 +190,7 @@ public function runLint(bool $isStandalone = true): int } if (isset($params['h'])) { - $this->usageLint($isStandalone); + $this->usageLint(); return 0; } @@ -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"; @@ -258,7 +258,7 @@ public function parseTokenize(): array|false return $params; } - public function runTokenize(bool $isStandalone = true): int + public function runTokenize(): int { $params = $this->parseTokenize(); if ($params === false) { @@ -266,7 +266,7 @@ public function runTokenize(bool $isStandalone = true): int } if (isset($params['h'])) { - $this->usageTokenize($isStandalone); + $this->usageTokenize(); return 0; } @@ -302,7 +302,7 @@ public function runTokenize(bool $isStandalone = true): int } echo "ERROR: Missing parameters!\n"; - $this->usageTokenize($isStandalone); + $this->usageTokenize(); return 1; } diff --git a/tests/Utils/CLITest.php b/tests/Utils/CLITest.php index 89e1a3009..124dc28f6 100644 --- a/tests/Utils/CLITest.php +++ b/tests/Utils/CLITest.php @@ -101,15 +101,15 @@ public static function highlightParamsProvider(): array ], [ ['h' => true], - 'Usage: highlight-query --query SQL [--format html|cli|text] [--ansi]' . "\n" . - ' cat file.sql | highlight-query' . "\n", + 'Usage: sql-parser --highlight --query SQL [--format html|cli|text] [--ansi]' . "\n" . + ' cat file.sql | sql-parser --highlight' . "\n", 0, ], [ [], 'ERROR: Missing parameters!' . "\n" . - 'Usage: highlight-query --query SQL [--format html|cli|text] [--ansi]' . "\n" . - ' cat file.sql | highlight-query' . "\n", + 'Usage: sql-parser --highlight --query SQL [--format html|cli|text] [--ansi]' . "\n" . + ' cat file.sql | sql-parser --highlight' . "\n", 1, ], [ @@ -164,16 +164,16 @@ public static function highlightParamsStdInProvider(): array [ '', ['h' => true], - 'Usage: highlight-query --query SQL [--format html|cli|text] [--ansi]' . "\n" . - ' cat file.sql | highlight-query' . "\n", + 'Usage: sql-parser --highlight --query SQL [--format html|cli|text] [--ansi]' . "\n" . + ' cat file.sql | sql-parser --highlight' . "\n", 0, ], [ '', [], 'ERROR: Missing parameters!' . "\n" . - 'Usage: highlight-query --query SQL [--format html|cli|text] [--ansi]' . "\n" . - ' cat file.sql | highlight-query' . "\n", + 'Usage: sql-parser --highlight --query SQL [--format html|cli|text] [--ansi]' . "\n" . + ' cat file.sql | sql-parser --highlight' . "\n", 1, ], [ @@ -227,15 +227,15 @@ public static function lintParamsStdInProvider(): array '', [], 'ERROR: Missing parameters!' . "\n" . - 'Usage: lint-query --query SQL [--ansi]' . "\n" . - ' cat file.sql | lint-query' . "\n", + 'Usage: sql-parser --lint --query SQL [--ansi]' . "\n" . + ' cat file.sql | sql-parser --lint' . "\n", 1, ], [ '', ['h' => true], - 'Usage: lint-query --query SQL [--ansi]' . "\n" . - ' cat file.sql | lint-query' . "\n", + 'Usage: sql-parser --lint --query SQL [--ansi]' . "\n" . + ' cat file.sql | sql-parser --lint' . "\n", 0, ], [ @@ -292,15 +292,15 @@ public static function lintParamsProvider(): array ], [ ['h' => true], - 'Usage: lint-query --query SQL [--ansi]' . "\n" . - ' cat file.sql | lint-query' . "\n", + 'Usage: sql-parser --lint --query SQL [--ansi]' . "\n" . + ' cat file.sql | sql-parser --lint' . "\n", 0, ], [ [], 'ERROR: Missing parameters!' . "\n" . - 'Usage: lint-query --query SQL [--ansi]' . "\n" . - ' cat file.sql | lint-query' . "\n", + 'Usage: sql-parser --lint --query SQL [--ansi]' . "\n" . + ' cat file.sql | sql-parser --lint' . "\n", 1, ], [ @@ -344,15 +344,15 @@ public static function tokenizeParamsProvider(): array ], [ ['h' => true], - 'Usage: tokenize-query --query SQL [--ansi]' . "\n" . - ' cat file.sql | tokenize-query' . "\n", + 'Usage: sql-parser --tokenize --query SQL [--ansi]' . "\n" . + ' cat file.sql | sql-parser --tokenize' . "\n", 0, ], [ [], 'ERROR: Missing parameters!' . "\n" . - 'Usage: tokenize-query --query SQL [--ansi]' . "\n" . - ' cat file.sql | tokenize-query' . "\n", + 'Usage: sql-parser --tokenize --query SQL [--ansi]' . "\n" . + ' cat file.sql | sql-parser --tokenize' . "\n", 1, ], [ @@ -393,16 +393,16 @@ public static function tokenizeParamsStdInProvider(): array [ '', ['h' => true], - 'Usage: tokenize-query --query SQL [--ansi]' . "\n" . - ' cat file.sql | tokenize-query' . "\n", + 'Usage: sql-parser --tokenize --query SQL [--ansi]' . "\n" . + ' cat file.sql | sql-parser --tokenize' . "\n", 0, ], [ '', [], 'ERROR: Missing parameters!' . "\n" . - 'Usage: tokenize-query --query SQL [--ansi]' . "\n" . - ' cat file.sql | tokenize-query' . "\n", + 'Usage: sql-parser --tokenize --query SQL [--ansi]' . "\n" . + ' cat file.sql | sql-parser --tokenize' . "\n", 1, ], [ @@ -431,27 +431,27 @@ public static function stdinParamsProvider(): array return [ [ - 'echo "SELECT 1" | ' . $binPath . 'highlight-query', + 'echo "SELECT 1" | ' . $binPath . 'sql-parser --highlight', 0, ], [ - 'echo "invalid query" | ' . $binPath . 'highlight-query', + 'echo "invalid query" | ' . $binPath . 'sql-parser --highlight', 0, ], [ - 'echo "SELECT 1" | ' . $binPath . 'lint-query', + 'echo "SELECT 1" | ' . $binPath . 'sql-parser --lint', 0, ], [ - 'echo "invalid query" | ' . $binPath . 'lint-query', + 'echo "invalid query" | ' . $binPath . 'sql-parser --lint', 10, ], [ - 'echo "SELECT 1" | ' . $binPath . 'tokenize-query', + 'echo "SELECT 1" | ' . $binPath . 'sql-parser --tokenize', 0, ], [ - 'echo "invalid query" | ' . $binPath . 'tokenize-query', + 'echo "invalid query" | ' . $binPath . 'sql-parser --tokenize', 0, ], ];