From 0ed58b6449f3376a3e53f774246d9b14d254e5fc Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Thu, 25 Jul 2019 10:48:38 +0200 Subject: [PATCH] add option -c --- README.md | 2 +- index.php | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 762890c..ab0dadd 100644 --- a/README.md +++ b/README.md @@ -26,4 +26,4 @@ hook_url = "https://mattermost.example.com/hooks/1234567890abcdefghijklm" message_template = "« %1$s » %2$s #foo #bar" ``` -Then run `php index.php`. +Then run `php index.php`. You can specify the path of the configuration file using `php index.php -c /path/to/config.ini`; diff --git a/index.php b/index.php index 54e414c..c841660 100644 --- a/index.php +++ b/index.php @@ -2,13 +2,16 @@ chdir(__DIR__); -$config = parse_ini_file('config.ini', true); +$options = getopt("c:"); + +$config = parse_ini_file($options['c'] ?? 'config.ini', true); $feedUrl = $config['feed']['url']; $hookUrl = $config['mattermost']['hook_url']; $cacheFile = $config['cache']['file']; $template = $config['mattermost']['message_template']; + if (file_exists($cacheFile)) { $cache = json_decode(file_get_contents($cacheFile), true);