Write CLI commands using Symfony Console: options, arguments, progress bars, colored output.
CLI Commands
class SendDigestCommand extends Command {
protected static $defaultName = "app:send-digest";
protected function configure(): void {
$this->addOption("dry-run", null, InputOption::VALUE_NONE, "Simulate")
->addOption("limit", "l", InputOption::VALUE_OPTIONAL, "Max", 100);
}
protected function execute(InputInterface $in, OutputInterface $out): int {
$out->writeln("Sending digest...");
if ($in->getOption("dry-run")) { $out->writeln("DRY RUN"); return Command::SUCCESS; }
// send emails...
$out->writeln("Done!");
return Command::SUCCESS;
}
}