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

if (\Phar::running() === '') {
    require_once __DIR__ . '/../bootstrap/autoload.php';
} else {
    require_once 'phar://' . \Phar::running(false) . '/bootstrap/autoload.php';
}

if (isset($argv[1]) && ($argv[1] === 'definitions' || $argv[1] === 'rules')) {
    try {
        $result = (new \AMWScan\Console\DefinitionApplication())->run(array_slice($argv, 1));
        if ($result !== null) {
            exit($result);
        }
    } catch (\Throwable $error) {
        fwrite(STDERR, 'Definition command failed: ' . $error->getMessage() . PHP_EOL);
        exit(2);
    }
}

exit((new \AMWScan\Console\Application())->run());