- $this->config = new Config();
- $this->config->load();
- $this->config->date = date('Y-m-d');
- setlocale(LC_TIME, $this->config->locale);
- $source = $this->config->loadSource();
-
- $parser = $this->loadParameters();
- $this->parseParameters($parser);
-
- $arEvents = $source->getEvents(
- $this->config->date,
- $this->config->daysPrev, $this->config->daysNext
- );
- usort($arEvents, '\\bdrem\\Event::compare');
- $this->render($arEvents);
+ try {
+ $this->config = new Config();
+ $parser = $this->loadParameters();
+ $res = $this->parseParameters($parser);
+
+ $this->config->load();
+ if (!$this->config->cfgFileExists) {
+ throw new \Exception(
+ "No config file found. Looked at the following places:\n"
+ . '- ' . implode ("\n- ", $this->config->cfgFiles)
+ );
+ }
+
+ setlocale(LC_TIME, $this->config->locale);
+ $this->handleCommands($res);
+
+ $source = $this->config->loadSource();
+ $arEvents = $source->getEvents(
+ $this->config->date,
+ $this->config->daysPrev, $this->config->daysNext
+ );
+ usort($arEvents, '\\bdrem\\Event::compare');
+ $this->render($arEvents);
+ } catch (\Exception $e) {
+ $this->preRenderParameterError();
+ echo 'Error: ' . $e->getMessage() . "\n";
+ exit(1);
+ }