/** * Runs the application, returning the status to exit with. * * @return integer The exit status. * @access public */ public function run() { $exit_status = 0; // Curator doesn't do anything without at least one argument, besides the curator command itself. if ($this->argc === 0) { Console::stdout('Use \'' . $this->cmd . ' --help\' for usage information.'); } else { try { $parser = $this->buildCommandLineParser(); $result = $parser->parse(); // determine where our relevant directories are. if (!empty($result->options['proj_path'])) { $project_dir = realpath($result->options['proj_path']); } if (empty($project_dir)) { $project_dir = $_SERVER['PWD']; } $this->createDirectoryAtPath($project_dir); try { $project = new Project($project_dir); switch ($result->command_name) { case 'new': $project->install(); break; case 'clean': $project->clean(); break; case 'build': $project->build(); break; } } catch (\Exception $e) { Console::stderr('** Command \'' . $result->command_name . '\' has failed:'); Console::stderr(' ' . $e->getMessage()); } } catch (\Exception $e) { $parser->displayError($e->getMessage()); $exit_status = $e->getCode(); } } return $exit_status; }