addArgument('name', InputArgument::REQUIRED, 'O nome do template (ex: users/index)') ->addOption('module', 'm', InputOption::VALUE_OPTIONAL, 'O módulo onde o template será criado'); } protected function execute(InputInterface $input, OutputInterface $output): int { $name = $input->getArgument('name'); $module = $input->getOption('module'); // Garante a extensão .twig if (!str_ends_with($name, '.twig')) { $name .= '.twig'; } if ($module) { $directory = dirname(__DIR__, 3) . "/modules/{$module}/views"; } else { $directory = dirname(__DIR__, 3) . "/templates"; } $filePath = $directory . '/' . $name; $fileDir = dirname($filePath); if (file_exists($filePath)) { $output->writeln("O template '{$name}' já existe!"); return Command::FAILURE; } if (!is_dir($fileDir)) { mkdir($fileDir, 0755, true); } $template = "{% extends \"layouts/base.twig\" %}\n\n{% block content %}\n
\n

" . ucfirst(basename($name, '.twig')) . "

\n

Novo template criado via CLI.

\n
\n{% endblock %}\n"; if (file_put_contents($filePath, $template)) { $output->writeln("Template '{$name}' criado com sucesso em " . ($module ? "modules/{$module}/views/" : "templates/") . ""); return Command::SUCCESS; } else { $output->writeln("Falha ao criar o arquivo do template."); return Command::FAILURE; } } }