addArgument('module', InputArgument::REQUIRED, 'O nome do módulo a ser ativado'); } protected function execute(InputInterface $input, OutputInterface $output): int { $moduleName = $input->getArgument('module'); $modulePath = dirname(__DIR__, 3) . '/modules/' . $moduleName . '/module.json'; if (!file_exists($modulePath)) { $output->writeln("Módulo '{$moduleName}' não encontrado ou arquivo module.json inexistente."); return Command::FAILURE; } $config = json_decode(file_get_contents($modulePath), true); if ($config === null) { $output->writeln("Erro ao ler o arquivo module.json do módulo '{$moduleName}'."); return Command::FAILURE; } $isActive = $config['module_active'] ?? $config['module_ative'] ?? false; if ($isActive === true) { $output->writeln("O módulo '{$moduleName}' já está ativado."); return Command::SUCCESS; } // Maintain the key already used in the file if possible if (isset($config['module_ative'])) { $config['module_ative'] = true; } else { $config['module_active'] = true; } if (file_put_contents($modulePath, json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES))) { $output->writeln("Módulo '{$moduleName}' ativado com sucesso!"); return Command::SUCCESS; } $output->writeln("Falha ao atualizar o arquivo module.json do módulo '{$moduleName}'."); return Command::FAILURE; } }