Los comandos CLI personalizados son útiles para mantenimiento, limpieza de datos y procesos recurrentes.
Clase del comando
Archivo Console/Command/HelloCommand.php:
<?phpnamespace GDW\Hello\Console\Command;
use Symfony\Component\Console\Command\Command;use Symfony\Component\Console\Input\InputInterface;use Symfony\Component\Console\Output\OutputInterface;
class HelloCommand extends Command{ protected function configure() { $this->setName('gdw:hello') ->setDescription('Comando de prueba GDW'); }
protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln('<info>Hola desde un comando custom</info>'); return 0; }}Registrar en DI
<type name="Magento\Framework\Console\CommandList"> <arguments> <argument name="commands" xsi:type="array"> <item name="gdw_hello" xsi:type="object">GDW\Hello\Console\Command\HelloCommand</item> </argument> </arguments></type>Ejecutar
bin/magento gdw:helloConclusión
Automatizar tareas con CLI evita errores manuales y acelera operaciones en entornos productivos.