<?php

namespace App\Services;

use Illuminate\Support\Fluent;
use function config;
use function fluent;

class Command extends \LaravelZero\Framework\Commands\Command
{

    protected Fluent $env;

    public function __construct()
    {
        parent::__construct();

        $this->loadProjectEnv();
    }


    public function loadProjectEnv(): void
    {

        $file = getcwd() . '/.env';

        if (!file_exists($file)) {
//            $this->error('No .env file found');
            return;
        }

        $this->env = fluent(parse_ini_file($file));

        config()->set('project.env', $this->env);

        $composeFiles = $this->env->get('CLI_COMPOSE_FILES');

        if ($composeFiles) {
            config()->set(
                'project.compose_files',
                array_map('trim', explode(',', $composeFiles)),
            );
        }
    }

}
