<?php

namespace App\Commands;

use App\Services\Command;
use App\Services\Docker;
use Illuminate\Support\Facades\Process;

class Package extends Command
{
    protected $signature = 'package {pkgAction}';

    protected $description = 'Run Command from a package.';

    public function handle() : void
    {
        $themeName = config('project.env')->get('THEME_NAME');
        $cwd = sprintf('%s/%s', config('project.themeCwd'), $themeName);

        $action = $this->argument('pkgAction');


        $cmd = match ($action) {
            'blocks.create' => './vendor/bin/blocks-cli wp:block:create',
            // Add more packages here
        };

        $upCommand = Docker::exec(command: $cmd, cwd: $cwd);

        Process::forever()->tty()->run($upCommand, function (string $type, string $output) {
            echo $output;
        });
    }

}
