#!/usr/bin/env php
<?php

/**
 * Starts tunneling service and register webhooks.
 * @author [deepeloper](https://github.com/deepeloper)
 * @license [MIT](https://opensource.org/licenses/mit-license.php)
 */

declare(strict_types=1);

namespace deepeloper\TunneledWebhooks;

error_reporting(E_ALL);

$binDir = getenv("COMPOSER_RUNTIME_BIN_DIR");
$binDir = false !== $binDir ? "$binDir/.." : "./vendor";
require_once "$binDir/autoload.php";
unset($binDir);

$output = [
    "Tunneled Webhooks",
    "",
];
if (2 != $argc) {
    $php = getenv("PHPBIN") ? getenv("PHPBIN") : "/path/to/php";
    $output[] = "Starts tunneling service and register appropriate webhooks.";
    $output[] = sprintf(
        "Usage: %s %s path/to/config",
        $php,
        $_SERVER['PHP_SELF'],
    );
    $output[] = "";
}

echo implode(PHP_EOL, $output);
if (2 != $argc) {
    die;
}

/**
 * Path to config file
 */
$path = $argv[1];

$runner = new Runner();
$runner->run(require_once $path);
