<?php

namespace kernel\console\controllers;

use kernel\console\ConsoleController;
use kernel\helpers\Files;
use kernel\services\KernelService;

class KernelController extends ConsoleController
{

    /**
     * @throws \Exception
     */
    public function actionPackKernel(): void
    {
        if (!isset($this->argv['path'])) {
            throw new \Exception('Missing kernel path "--path" specified');
        }

        if (file_exists(ROOT_DIR . $this->argv['path'])) {

            $tmpKernelDirFull = RESOURCES_DIR . '/tmp/ad/kernel/';

            $fileHelper = new Files();
            $fileHelper->copy_folder(KERNEL_DIR, $tmpKernelDirFull);

            $fileHelper->pack($tmpKernelDirFull, RESOURCES_DIR . '/tmp/kernel/kernel.itguild');

            $fileHelper->recursiveRemoveDir($tmpKernelDirFull);
            $this->out->r("Ядро заархивировано", 'green');
        } else {
            $this->out->r("Ядро не найдено", 'red');
        }
    }

}