function run($argv = null)
{
try {
$this->opts->parse($argv);
} catch (Optparse\Exception $e) {
fwrite(STDERR, "{$e->getMessage()}\n\n");
fwrite(STDERR, $this->formatUsage());
return 1;
}
$this->application['log.verbose'] = (bool) $this->opts['verbose'];
$this->application->trace = $this->trace;
$this->application->forceRun = $this->forceRun;
if ($this->opts['version']) {
printf("Bob %s\n", \Bob::VERSION);
return 0;
}
if ($this->opts["init"]) {
return $this->initProject() ? 0 : 1;
}
if ($this->opts["help"]) {
fwrite(STDERR, $this->formatUsage());
return 0;
}
if ($dir = $this->opts["chdir"]) {
if (!is_dir($dir)) {
$this->logger()->err(sprintf('Directory not found: "%s"', $dir));
return 1;
}
$this->logger()->info(sprintf('Changing working directory to "%s"', realpath($dir)));
chdir($dir);
}
$this->application['config.load_path'] = array_merge($this->application['config.load_path'], explode(':', @$_SERVER['BOB_CONFIG_PATH']));
try {
$this->application->init();
} catch (\Exception $e) {
fwrite(STDERR, $e);
return 127;
}
if ($this->opts["tasks"]) {
fwrite(STDERR, $this->formatTasksAndDescriptions());
return 0;
}
$this->withErrorHandling(array($this, 'runTasks'));
}