[ 'autoregister_zf' => true, ], ]); require_once __DIR__ . '/Hart.php'; // MAIN $opts = new Zend\Console\Getopt([ 'user|u-s' => 'Basic Auth user', 'line|l-s' => 'Line number or range, e.g: -l 10, -l 10:20, -l 10:', 'no-success' => 'Don\'t show success lines', 'password|p-s' => 'Basic Auth password', 'format|f-s' => 'format output (yt - YouTrack, html - HTML page, console - default)', 'version|v' => 'version', 'help|h' => 'help', ]); $opts->setOptionCallback('l', function ($line, Zend\Console\Getopt $opts) { $matches = []; if (preg_match('/^(\d+)\:?(\d+)?$/', $line, $matches)) { $start = $matches[1]; $end = isset($matches[2]) ? $matches[2] : null; if (null !== $end && $end <= $start) { return false; } } return true; }); $printHelp = function () use ($opts) { $message = $opts->getUsageMessage(); $message = str_replace('[ options ]', 'FILE [ options ]' . PHP_EOL, $message); echo APPLICATION_ID . PHP_EOL . PHP_EOL . $message . PHP_EOL . 'Example: hart.phar .htaccess -u tester -p test -f html > report.html' . PHP_EOL . PHP_EOL; }; try { $opts->parse(); } catch (Exception $e) { echo $e->getMessage(), PHP_EOL, PHP_EOL; $printHelp(); exit; } if ($opts->getOption('h')) { die($opts->getUsageMessage()); } if ($opts->getOption('v')) { die('Version: ' . APPLICATION_ID . PHP_EOL); } if (!($opts->getRemainingArgs())) { $printHelp(); exit; } $file = current($opts->getRemainingArgs()); $test = new Hart(); switch ($opts->getOption('f')) { case 'yt': $test->setFormat(Hart::FORMAT_YOUTRACK); break; case 'html': $test->setFormat(Hart::FORMAT_HTML); break; case '': case 'console': $test->setFormat(Hart::FORMAT_CONSOLE); break; default: die('Invalid format: ' . $opts->getOption('format')); } if ($opts->getOption('no-success')) { $test->setNoSuccess(true); } if (($line = $opts->getOption('l'))) { $test->setFilterLines($line); } if (($user = $opts->getOption('u')) && ($password = $opts->getOption('p'))) { $test->setCredentials($user, $password); } $test->run($file); echo PHP_EOL;