/** * Invokes the command. * * Needs opts like: getopt("s:f:o:hd"). * Returns error codes defined as class constants. * * @param array $opts Command line arguments. * @param string $baseName Teh script which invokes the command, default is 'ebnf'. * * @return int */ public static function main(array $opts, $baseName = "ebnf") { $debug = false; if (isset($opts["d"])) { $debug = true; } try { $self = new Command($opts, $baseName); return $self->execute(); } catch (SyntaxtException $e) { echo "{$e}\n"; if ($debug) { echo "{$e->getTraceAsString()}\n"; } return self::EBNF_SYNTAX_ERROR; } catch (Exception $e) { echo "Error: {$e->getMessage()}\n"; if ($debug) { echo "{$e->getTraceAsString()}\n"; } return self::EBNF_FATAL_ERROR; } }