<?php

declare(strict_types=1);

require_once __DIR__ . '/support.php';

$options = scripts_parse_options($argv);
$outputPath = scripts_bundle_output_path();
$connection = scripts_normalize_db_connection($options['connection'] ?? scripts_read_env_file(scripts_env_path())['DB_CONNECTION'] ?? 'mysql');

foreach (array_slice($argv, 1) as $arg) {
    if (scripts_string_starts_with($arg, '--')) {
        continue;
    }

    $outputPath = $arg;
    break;
}

try {
    scripts_stdout(scripts_build_migration_bundle($outputPath, $connection));
} catch (Throwable $exception) {
    scripts_stderr($exception->getMessage());
}
