X-Git-Url: https://git.cweiske.de/auerswald-callnotifier.git/blobdiff_plain/19e5e158f8a6e9dda406c2eb70ad035211613df8..706ce1501a9ab1a33e4106774665c631a3ad3749:/src/callnotifier/CLI.php diff --git a/src/callnotifier/CLI.php b/src/callnotifier/CLI.php index 4bc0e60..928e4ce 100644 --- a/src/callnotifier/CLI.php +++ b/src/callnotifier/CLI.php @@ -4,10 +4,79 @@ namespace callnotifier; class CLI { + protected $cliParser; + protected $config; + + public function __construct() + { + $this->setupCli(); + } + public function run() { - $s = new Socket('192.168.3.95'); - $s->run(); + $this->config = new Config(); + try { + $result = $this->cliParser->parse(); + } catch (\Exception $exc) { + $this->cliParser->displayError($exc->getMessage()); + } + + $this->fillConfig($this->config, $result); + + $handler = new MessageHandler($this->config); + if ($this->config->replayFile !== null) { + $sourceClass = 'callnotifier\Source_File'; + } else { + $sourceClass = 'callnotifier\Source_Remote'; + } + $source = new $sourceClass($this->config, $handler); + $source->run(); + } + + public function setupCli() + { + $p = new \Console_CommandLine(); + $p->description = 'Notifies about incoming calls on an Auerswald COMpact 3000'; + $p->version = '0.0.1'; + + $p->addOption( + 'host', + array( + 'short_name' => '-h', + 'long_name' => '--host', + 'description' => 'IP of COMpact 3000', + 'help_name' => 'IP', + 'action' => 'StoreString' + ) + ); + + $p->addOption( + 'dumpFile', + array( + 'long_name' => '--dump', + 'description' => 'dump messages into file for later replay', + 'help_name' => 'FILE', + 'action' => 'StoreString' + ) + ); + $p->addOption( + 'replayFile', + array( + 'long_name' => '--replay', + 'description' => "Replay messages from file instead from network", + 'help_name' => 'FILE', + 'action' => 'StoreString' + ) + ); + + $this->cliParser = $p; + } + + protected function fillConfig($config, $result) + { + $config->setIfNotEmpty('host', $result->options['host']); + $config->setIfNotEmpty('dumpFile', $result->options['dumpFile']); + $config->setIfNotEmpty('replayFile', $result->options['replayFile']); } }