/** * Main function. Sets up the environment and coordinate the work. * * @return void */ public static function run() { // Set autoload up require_once 'VcsStats/Loader.php'; spl_autoload_register(array('VcsStats_Loader', 'autoload')); require_once 'ezc/Base/base.php'; spl_autoload_register(array('ezcBase', 'autoload')); // Set console output up $output = new ezcConsoleOutput(); $output->formats->version->style = array('bold'); $output->formats->debug->color = 'yellow'; $output->formats->debug->style = array('italic'); $output->formats->error->color = 'red'; self::$consoleOutput = $output; // Set console input up $input = new ezcConsoleInput(); self::$consoleInput = $input; $debugOption = new ezcConsoleOption('d', 'debug'); $debugOption->type = ezcConsoleInput::TYPE_NONE; $input->registerOption($debugOption); $helpOption = new ezcConsoleOption('h', 'help'); $helpOption->type = ezcConsoleInput::TYPE_NONE; $input->registerOption($helpOption); $revisionsOption = new ezcConsoleOption('r', 'revisions'); $revisionsOption->type = ezcConsoleInput::TYPE_STRING; $input->registerOption($revisionsOption); $verboseOption = new ezcConsoleOption('v', 'verbose'); $verboseOption->type = ezcConsoleInput::TYPE_NONE; $input->registerOption($verboseOption); $versionOption = new ezcConsoleOption(null, 'version'); $versionOption->type = ezcConsoleInput::TYPE_NONE; $input->registerOption($versionOption); // Process console input try { $input->process(); } catch (ezcConsoleOptionException $exception) { echo $exception->getMessage() . "\n"; exit(1); } if ($input->getOption('help')->value) { self::displayHelp(); exit(0); } else { if ($input->getOption('version')->value) { self::displayVersion(); exit(0); } } $arguments = $input->getArguments(); if (1 !== count($arguments)) { self::displayError('Path to repository is missing', 'error'); exit(1); } $repositoryPath = $arguments[0]; // Do the actual work self::displayVersion(); try { $options = array('path' => $repositoryPath); $wrapper = new VcsStats_Wrapper_Subversion($options); $cachePath = realpath(dirname(__FILE__) . '/../../tmp'); $cache = new VcsStats_Cache($wrapper, $cachePath); $revisionsRange = self::_extractRevisionsRange($input->getOption('revisions')->value); $cache->updateData($revisionsRange['end']); $analyzer = new VcsStats_Analyzer($cache); $report = $analyzer->getReport($revisionsRange['start'], $revisionsRange['end']); $renderer = new VcsStats_Renderer_Text(); $renderer->render($report); } catch (Exception $exception) { self::displayError($exception->getMessage()); exit(1); } }