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

$autoloads = [
	__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php', // we're not a dependency
	__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'autoload.php' // we're in a vendor/bin dir
];

foreach ($autoloads as $path)
{
	if (file_exists($path))
	{
		require $path;
		break;
	}
}

$worker = new djfm\ftr\Worker();

$settings = @json_decode($argv[1], true);

if (!is_array($settings)) {
	exit(1);
}

$worker->setup($settings);

$status = $worker->run();

exit($status ? 0 : 2);
