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

declare(strict_types=1);

use Composer\InstalledVersions;
use JDecool\ScalewayRuntime\Packager;

require $_composer_autoload_path ?? __DIR__.'/../vendor/autoload.php';

if (in_array($argv[1] ?? null, ['-h', '--help'], true)) {
    echo 'Usage: scaleway-package [<zip-file>]  (default: function.zip)', \PHP_EOL;
    exit(0);
}

try {
    (new Packager((string) realpath(InstalledVersions::getRootPackage()['install_path']), \STDERR))->package($argv[1] ?? 'function.zip');
} catch (Throwable $e) {
    fwrite(\STDERR, 'Packaging failed: '.$e->getMessage().\PHP_EOL);
    exit(1);
}
