#!/usr/bin/php getMessage() . "\n", 'red', 'bold'); die(); } // Set up all available search paths for cli commands $command_paths = array(); $command_paths['main'] = THEBUGGENIE_PATH . 'modules' . DS . 'main' . DS . 'classes' . DS . 'cli' . DS; $command_paths['remote'] = THEBUGGENIE_PATH . 'modules' . DS . 'remote' . DS . 'classes' . DS . 'cli' . DS; foreach (TBGContext::getModules() as $module_name => $module) { $module_cli_path = THEBUGGENIE_PATH . 'modules' . DS . $module_name . DS . 'classes' . DS . 'cli' . DS; if (file_exists($module_cli_path)) { $command_paths[$module_name] = $module_cli_path; } } // Set up all cli commands $commands = array('main' => array()); foreach ($command_paths as $module_name => $command_path) { TBGContext::addClasspath($command_path); $_path_handle = opendir($command_path); while ($command_class_file = readdir($_path_handle)) { if (($classname = substr($command_class_file, 0, strpos($command_class_file, '.'))) != '') { $command = new $classname(); if ($command instanceof TBGCliCommand) { $commands[$module_name][$command->getCommandName()] = $command; foreach ($command->getCommandAliases() as $alias) { $commands[$module_name][$alias] = $command; } } } } } TBGCliCommand::setAvailableCommands($commands); if ($argc < 2) { // Show usage if no parameters are provided TBGCliCommand::cli_echo("The Bug Genie command line tool\n\n"); TBGCliCommand::cli_echo("Usage: ", 'white', 'bold'); TBGCliCommand::cli_echo(TBGCliCommand::getCommandLineName() . " ["); TBGCliCommand::cli_echo('command', 'green', 'bold'); TBGCliCommand::cli_echo("]\n"); TBGCliCommand::cli_echo("Type " . TBGCliCommand::getCommandLineName() . ' '); TBGCliCommand::cli_echo('help', 'green', 'bold'); TBGCliCommand::cli_echo(" for more information.\n\n"); } else { // Process arguments and invoke command if available try { TBGCliCommand::processArguments(); $module_command = explode(':', $argv[1]); $module_name = (count($module_command) == 2) ? $module_command[0] : 'main'; $command = (count($module_command) == 2) ? $module_command[1] : $module_command[0]; if (array_key_exists($module_name, $commands) && array_key_exists($command, $commands[$module_name])) { $class = $commands[$module_name][$command]; TBGContext::setCLIRouting($module_name, $command); $class->execute(); } else { TBGCliCommand::cli_echo("\n"); TBGCliCommand::cli_echo("Unknown command\n", 'red', 'bold'); TBGCliCommand::cli_echo("Type " . TBGCliCommand::getCommandLineName() . ' '); TBGCliCommand::cli_echo('help', 'green', 'bold'); TBGCliCommand::cli_echo(" for more information about the cli tool.\n\n"); } } catch (Exception $e) { TBGCliCommand::cli_echo("\n"); TBGCliCommand::cli_echo("The following error occured:\n", 'red', 'bold'); TBGCliCommand::cli_echo($e->getMessage()."\n\n", 'red'); TBGCliCommand::cli_echo("Type " . TBGCliCommand::getCommandLineName() . ' '); TBGCliCommand::cli_echo('help', 'green', 'bold'); TBGCliCommand::cli_echo(" for more information about the cli tool.\n\n"); } } return true;