|
18 | 18 |
|
19 | 19 | echo 'JSON Schema Validator @git-version@ by nerou GmbH'.PHP_EOL.PHP_EOL; |
20 | 20 |
|
21 | | -$cliArgs = new CLIParser($_SERVER['argv']); |
| 21 | +$cliArgs = new CLIParser($_SERVER['argv'], 'schema_file1.json schema_folder2 [...]'); |
22 | 22 | $cliArgs->setAllowedOptions([]); |
23 | 23 | $cliArgs->setAllowedFlags([]); |
24 | 24 | $cliArgs->setStrictMode(true); |
25 | 25 | if(!$cliArgs->parse() || empty($cliArgs->getCommands())){ |
26 | | - echo 'usage: php '.basename(__FILE__).' schema_file1.json schema_folder2 [...]'.PHP_EOL; |
| 26 | + $cliArgs->printUsage(); |
27 | 27 | exit(2); |
28 | 28 | } |
29 | 29 |
|
|
32 | 32 | try { |
33 | 33 | $files = collectSchemaFiles($cliArgs->getCommands()); |
34 | 34 | } catch(\InvalidArgumentException $ex){ |
35 | | - echo "\033[31m".$ex->getMessage()."\033[0m".PHP_EOL; |
| 35 | + echo "\e[31m".$ex->getMessage()."\e[0m".PHP_EOL; |
36 | 36 | exit(20); |
37 | 37 | } |
38 | 38 |
|
|
59 | 59 | */ |
60 | 60 | $json = json_decode($fileContent, flags: JSON_THROW_ON_ERROR); |
61 | 61 | } catch(JsonException $ex){ |
62 | | - echo "[\033[31mSYNTAX ERROR\033[0m]".PHP_EOL; |
| 62 | + echo "[\e[31mSYNTAX ERROR\e[0m]".PHP_EOL; |
63 | 63 | $errors++; |
64 | 64 | continue; |
65 | 65 | } |
|
76 | 76 | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR); |
77 | 77 | $errorMessage = str_replace('%24', '$', $errorMessage); |
78 | 78 | $errorMessage = indent($errorMessage, $countChars * 2 + 4); |
79 | | - echo "[\033[31mSCHEMA ERROR\033[0m]".PHP_EOL.$errorMessage.PHP_EOL; |
| 79 | + echo "[\e[31mSCHEMA ERROR\e[0m]".PHP_EOL.$errorMessage.PHP_EOL; |
80 | 80 | $errors++; |
81 | 81 | } else { |
82 | | - echo "[\033[32mOK\033[0m]".PHP_EOL; |
| 82 | + echo "[\e[32mOK\e[0m]".PHP_EOL; |
83 | 83 | } |
84 | 84 | } catch(\ErrorException $ex){ |
85 | 85 | if(mb_strpos($ex->getMessage(), 'preg_match(): Compilation failed: ') === 0){ |
86 | | - echo "[\033[31mSYNTAX ERROR\033[0m]".PHP_EOL.indent($ex->getMessage(), $countChars * 2 + 4).PHP_EOL; |
| 86 | + echo "[\e[31mSYNTAX ERROR\e[0m]".PHP_EOL.indent($ex->getMessage(), $countChars * 2 + 4).PHP_EOL; |
87 | 87 | $errors++; |
88 | 88 | } else { |
89 | 89 | throw $ex; |
|
0 commit comments