diff --git a/parallel-lint b/parallel-lint index cb320718..9b6ac4f3 100755 --- a/parallel-lint +++ b/parallel-lint @@ -1,4 +1,63 @@ #!/usr/bin/env php run(); diff --git a/parallel-lint.php b/parallel-lint.php deleted file mode 100644 index ee0e5dbf..00000000 --- a/parallel-lint.php +++ /dev/null @@ -1,129 +0,0 @@ - -Options: - -p Specify PHP-CGI executable to run (default: 'php'). - -s, --short Set short_open_tag to On (default: Off). - -a, -asp Set asp_tags to On (default: Off). - -e Check only files with selected extensions separated by comma. - (default: php,php3,php4,php5,phtml,phpt) - --exclude Exclude a file or directory. If you want exclude multiple items, - use multiple exclude parameters. - -j Run jobs in parallel (default: 10). - --colors Enable colors in console output. (disables auto detection of color support) - --no-colors Disable colors in console output. - --no-progress Disable progress in console output. - --json Output results as JSON string. - --checkstyle Output results as Checkstyle XML. - --blame Try to show git blame for row with error. - --git Path to Git executable to show blame message (default: 'git'). - --stdin Load files and folder to test from standard input. - --ignore-fails Ignore failed tests. - -h, --help Print this help. - -V, --version Display this application version - -------------------------------- -Usage: - parallel-lint [sa] [-p php] [-e ext] [-j num] [--exclude dir] [files or directories] - -stdin) { - $settings->addPaths(PhpParallelLint\Settings::getPathsFromStdIn()); - } - - if (empty($settings->paths)) { - showUsage(); - } - - $manager = new PhpParallelLint\Manager; - $result = $manager->run($settings); - - if ($settings->ignoreFails) { - die($result->hasSyntaxError() ? WITH_ERRORS : SUCCESS); - } else { - die($result->hasError() ? WITH_ERRORS : SUCCESS); - } - -} catch (PhpParallelLint\InvalidArgumentException $e) { - echo "Invalid option {$e->getArgument()}", PHP_EOL, PHP_EOL; - showOptions(); - die(FAILED); - -} catch (PhpParallelLint\Exception $e) { - if (isset($settings) && $settings->format === PhpParallelLint\Settings::FORMAT_JSON) { - echo json_encode($e); - } else { - echo $e->getMessage(), PHP_EOL; - } - die(FAILED); - -} catch (Exception $e) { - echo $e->getMessage(), PHP_EOL; - die(FAILED); -} diff --git a/src/Application.php b/src/Application.php new file mode 100644 index 00000000..3833fef7 --- /dev/null +++ b/src/Application.php @@ -0,0 +1,146 @@ +showUsage(); + } + if (in_array('-V', $_SERVER['argv']) || in_array('--version', $_SERVER['argv'])) { + $this->showVersion(); + die(); + } + try { + $settings = Settings::parseArguments($_SERVER['argv']); + if ($settings->stdin) { + $settings->addPaths(Settings::getPathsFromStdIn()); + } + if (empty($settings->paths)) { + $this->showUsage(); + } + $manager = new Manager; + $result = $manager->run($settings); + if ($settings->ignoreFails) { + die($result->hasSyntaxError() ? self::WITH_ERRORS : self::SUCCESS); + } else { + die($result->hasError() ? self::WITH_ERRORS : self::SUCCESS); + } + } catch (InvalidArgumentException $e) { + echo "Invalid option {$e->getArgument()}", PHP_EOL, PHP_EOL; + $this->showOptions(); + die(self::FAILED); + } catch (Exception $e) { + if (isset($settings) && $settings->format === Settings::FORMAT_JSON) { + echo json_encode($e); + } else { + echo $e->getMessage(), PHP_EOL; + } + die(self::FAILED); + } catch (Exception $e) { + echo $e->getMessage(), PHP_EOL; + die(self::FAILED); + } + } + + /** + * Outputs the options + */ + private function showOptions() + { + echo << Specify PHP-CGI executable to run (default: 'php'). + -s, --short Set short_open_tag to On (default: Off). + -a, -asp Set asp_tags to On (default: Off). + -e Check only files with selected extensions separated by comma. + (default: php,php3,php4,php5,phtml,phpt) + --exclude Exclude a file or directory. If you want exclude multiple items, + use multiple exclude parameters. + -j Run jobs in parallel (default: 10). + --colors Enable colors in console output. (disables auto detection of color support) + --no-colors Disable colors in console output. + --no-progress Disable progress in console output. + --json Output results as JSON string. + --checkstyle Output results as Checkstyle XML. + --blame Try to show git blame for row with error. + --git Path to Git executable to show blame message (default: 'git'). + --stdin Load files and folder to test from standard input. + --ignore-fails Ignore failed tests. + -h, --help Print this help. + -V, --version Display this application version + +HELP; + } + + /** + * Outputs the current version + */ + private function showVersion() + { + echo 'PHP Parallel Lint version ' . self::VERSION.PHP_EOL; + } + + /** + * Shows usage + */ + private function showUsage() + { + $this->showVersion(); + echo <<showOptions(); + die(); + } +}